added screenshots and debug env

This commit is contained in:
Thephaseless 2024-07-24 20:38:23 +00:00
parent 89756292a7
commit 213602b37a
2 changed files with 12 additions and 0 deletions

View File

@ -4,5 +4,9 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
environment:
- LOG_LEVEL=DEBUG
ports: ports:
- "8191:8191" - "8191:8191"
volumes:
- ./screenshots:/app/screenshots

View File

@ -1,3 +1,6 @@
import os
from pathlib import Path
import nodriver as webdriver import nodriver as webdriver
from nodriver.core.element import Element from nodriver.core.element import Element
@ -9,6 +12,7 @@ from src.utils.utils import CHALLENGE_TITLES
async def new_browser(): async def new_browser():
config: webdriver.Config = webdriver.Config() config: webdriver.Config = webdriver.Config()
config.sandbox = False config.sandbox = False
config.headless = bool(os.getenv("HEADLESS"))
config.add_argument(f"--load-extension={','.join(downloaded_extentions)}") config.add_argument(f"--load-extension={','.join(downloaded_extentions)}")
return await webdriver.start(config=config) return await webdriver.start(config=config)
@ -23,7 +27,11 @@ async def bypass_cloudflare(page: webdriver.Tab):
return challenged return challenged
if not challenged: if not challenged:
logger.info("Found challenge") logger.info("Found challenge")
await page.save_screenshot(Path("screenshots/screenshot.png"))
challenged = True 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") elem = await page.query_selector(".cf-turnstile-wrapper")
if isinstance(elem, Element): if isinstance(elem, Element):
await elem.mouse_click() await elem.mouse_click()