added screenshots and debug env

This commit is contained in:
ThePhaseless
2024-07-24 20:38:23 +00:00
parent 031235dba1
commit 427c758de6
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -4,5 +4,9 @@ services:
build:
context: .
dockerfile: Dockerfile
environment:
- LOG_LEVEL=DEBUG
ports:
- "8191:8191"
volumes:
- ./screenshots:/app/screenshots
+8
View File
@@ -1,3 +1,6 @@
import os
from pathlib import Path
import nodriver as webdriver
from nodriver.core.element import Element
@@ -9,6 +12,7 @@ from src.utils.utils import CHALLENGE_TITLES
async def new_browser():
config: webdriver.Config = webdriver.Config()
config.sandbox = False
config.headless = bool(os.getenv("HEADLESS"))
config.add_argument(f"--load-extension={','.join(downloaded_extentions)}")
return await webdriver.start(config=config)
@@ -23,7 +27,11 @@ async def bypass_cloudflare(page: webdriver.Tab):
return challenged
if not challenged:
logger.info("Found challenge")
await page.save_screenshot(Path("screenshots/screenshot.png"))
challenged = True
Path("screenshots").mkdir(exist_ok=True)
logger.debug("Clicking element")
await page.save_screenshot(Path("screenshots/screenshot.png"))
elem = await page.query_selector(".cf-turnstile-wrapper")
if isinstance(elem, Element):
await elem.mouse_click()