2024-07-25 00:39:29 +00:00
|
|
|
import asyncio
|
2024-07-24 20:38:23 +00:00
|
|
|
|
2024-07-24 13:57:40 +00:00
|
|
|
import nodriver as webdriver
|
|
|
|
from nodriver.core.element import Element
|
|
|
|
|
|
|
|
from src.utils import logger
|
2024-07-25 00:06:56 +00:00
|
|
|
from src.utils.consts import CHALLENGE_TITLES
|
2024-07-24 15:16:46 +00:00
|
|
|
from src.utils.extentions import downloaded_extentions
|
2024-07-24 13:57:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def new_browser():
|
|
|
|
config: webdriver.Config = webdriver.Config()
|
|
|
|
config.sandbox = False
|
2024-07-24 15:16:46 +00:00
|
|
|
config.add_argument(f"--load-extension={','.join(downloaded_extentions)}")
|
2024-07-24 13:57:40 +00:00
|
|
|
|
|
|
|
return await webdriver.start(config=config)
|
|
|
|
|
|
|
|
|
|
|
|
async def bypass_cloudflare(page: webdriver.Tab):
|
|
|
|
challenged = False
|
|
|
|
while True:
|
|
|
|
await page.wait(0.5)
|
2024-07-25 00:39:29 +00:00
|
|
|
logger.debug(f"Current page: {page.target.title}")
|
2024-07-24 13:57:40 +00:00
|
|
|
if page.target.title not in CHALLENGE_TITLES:
|
|
|
|
return challenged
|
2024-07-24 15:16:46 +00:00
|
|
|
if not challenged:
|
|
|
|
logger.info("Found challenge")
|
|
|
|
challenged = True
|
2024-07-25 00:39:29 +00:00
|
|
|
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
|
2024-07-24 13:57:40 +00:00
|
|
|
if isinstance(elem, Element):
|
|
|
|
await elem.mouse_click()
|