fix: добавление обхода для recaptcha

This commit is contained in:
protokey committed 2026-09-18 19:15:44 +04:00
1 parent b77f25d3cd
commit 4cc068a616
5 files changed
+130 -49

No files matched your search

+35 -1
View File
@@ -6,12 +6,46 @@
- селектор со страницы (достаточно общий чтобы покрыть весь сайт, но не страницу антибот защиты)
- ключ сервиса распознавания капчи
"""
from copy import deepcopy
import asyncio
from dataclasses import dataclass
from enum import Enum
from typing import Type
from playwright.async_api import Page
from playwright.async_api import TimeoutError as PWTimeoutError
async def click_and_race(page, element, challenge_locator, timeout=30_000):
nav_task = asyncio.create_task(
page.wait_for_event(
"framenavigated",
predicate=lambda frame: frame == page.main_frame,
timeout=timeout,
)
)
challenge_task = asyncio.create_task(
challenge_locator.wait_for(state="attached", timeout=timeout)
)
await element.click()
done, pending = await asyncio.wait(
{nav_task, challenge_task}, return_when=asyncio.FIRST_COMPLETED
)
for t in pending:
t.cancel()
if nav_task in done and nav_task.exception() is None:
return "navigation"
if challenge_task in done and challenge_task.exception() is None:
return "challenge"
# оба протухли по таймауту / или упали с другой ошибкой
for t in done:
exc = t.exception()
if exc and not isinstance(exc, PWTimeoutError):
raise exc
raise PWTimeoutError("Ни навигация, ни challenge-iframe не появились вовремя")
class Stage(str, Enum):