Skip to content

Commit

Permalink
remove screenshots, improve logging and add timeout for button
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhaseless committed Jul 25, 2024
1 parent 0178eee commit ede99e0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/utils/browser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pathlib import Path
import asyncio

import nodriver as webdriver
from nodriver.core.element import Element
Expand All @@ -19,18 +19,19 @@ async def new_browser():
async def bypass_cloudflare(page: webdriver.Tab):
challenged = False
while True:
await page
await page.wait(0.5)
logger.debug(page.target.title)
logger.debug(f"Current page: {page.target.title}")
if page.target.title not in CHALLENGE_TITLES:
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")
try:
elem = await asyncio.wait_for(
page.query_selector(".cf-turnstile-wrapper"), timeout=3
)
except asyncio.TimeoutError:
logger.warning("Timed out waiting for element, trying again")
continue
if isinstance(elem, Element):
await elem.mouse_click()

0 comments on commit ede99e0

Please sign in to comment.