logic refactor

This commit is contained in:
Thephaseless 2024-10-18 14:50:43 +00:00
parent 99c90ddc23
commit 90b6c4d512

View File

@ -66,23 +66,32 @@ async def bypass_cloudflare(page: webdriver.Tab):
if not challenged: if not challenged:
logger.info("Found challenge") logger.info("Found challenge")
challenged = True challenged = True
try:
elem = await page.find("lds-ring", timeout=3)
except asyncio.TimeoutError:
logger.debug("Challenge loaded")
else:
logger.debug("Challenge still loading")
continue
await page
try: try:
elem = await page.find( elem = await page.find(
"Verify you are human by completing the action below.", "Verify you are human by completing the action below.",
timeout=3, timeout=1,
) )
# If challenge solves by itself # If challenge solves by itself
except asyncio.TimeoutError: except asyncio.TimeoutError:
if page.target.title not in CHALLENGE_TITLES: if page.target.title not in CHALLENGE_TITLES:
return challenged return challenged
if elem is None: logger.debug(msg=f"Clicking element {elem}")
logger.debug("Couldn't find the title, trying other method...") if isinstance(elem, Element):
await elem.mouse_click()
continue continue
if not isinstance(elem, Element): logger.debug("Couldn't find the title, trying other method...")
raise InvalidElementError
elem = await page.find("input") elem = await page.find("input")
elem = elem.parent elem = elem.parent
# Get the element containing the shadow root # Get the element containing the shadow root
@ -96,6 +105,7 @@ async def bypass_cloudflare(page: webdriver.Tab):
logger.warning( logger.warning(
"Element is a string, please report this to Byparr dev" "Element is a string, please report this to Byparr dev"
) # I really hope this never happens ) # I really hope this never happens
logger.warning(inner_elem)
else: else:
logger.warning("Coulnd't find checkbox, trying again...") logger.warning("Coulnd't find checkbox, trying again...")