From bce08edcca1cae2a9589be4c185e1a807bed8bcc Mon Sep 17 00:00:00 2001 From: Mynacol Date: Fri, 13 Jun 2025 23:29:00 +0000 Subject: [PATCH 1/2] Adapt to update of hcaptcha_challenger --- botright/botright.py | 3 --- botright/modules/hcaptcha.py | 34 +++++++++++++++------------------- requirements.txt | 4 ++-- setup.cfg | 2 +- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/botright/botright.py b/botright/botright.py index 10f08b4..1fb76ef 100644 --- a/botright/botright.py +++ b/botright/botright.py @@ -7,7 +7,6 @@ from typing import Any, Dict, List, Optional import browsers -import hcaptcha_challenger as solver import loguru from async_class import AsyncObject from chrome_fingerprints import AsyncFingerprintGenerator @@ -77,8 +76,6 @@ async def __ainit__( use_undetected_playwright (bool, optional): Whether to use undetected_playwright . EXPERIMENTAL (TEMP). Defaults to False. """ - # Init local-side of the ModelHub - solver.install(upgrade=True) # Starting Playwright if use_undetected_playwright: # (TODO: TEMP) diff --git a/botright/modules/hcaptcha.py b/botright/modules/hcaptcha.py index 02cbdca..e2de6bc 100644 --- a/botright/modules/hcaptcha.py +++ b/botright/modules/hcaptcha.py @@ -3,13 +3,12 @@ from pathlib import Path from typing import TYPE_CHECKING, Optional -from hcaptcha_challenger.agents import AgentT +from hcaptcha_challenger.agent import AgentV, AgentConfig +from hcaptcha_challenger.models import ChallengeSignal if TYPE_CHECKING: from botright.extended_typing import BrowserContext, Page -tmp_dir = Path(__file__).parent.joinpath("tmp_dir") - class hCaptcha: def __init__(self, browser: BrowserContext, page: Page) -> None: @@ -23,8 +22,7 @@ def __init__(self, browser: BrowserContext, page: Page) -> None: self.browser = browser self.page = page - self.retry_times = 8 - self.hcaptcha_agent = AgentT.from_page(page=page, tmp_dir=tmp_dir, self_supervised=True) + self.hcaptcha_agent = AgentV(page=page, agent_config=AgentConfig()) async def mock_captcha(self, rq_data: str) -> None: """ @@ -61,20 +59,18 @@ async def solve_hcaptcha(self, rq_data: Optional[str] = None) -> Optional[str]: if rq_data: await self.mock_captcha(rq_data) # Clicking Captcha Checkbox - await self.hcaptcha_agent.handle_checkbox() - - for pth in range(1, self.retry_times): - result = await self.hcaptcha_agent.execute() - if result == self.hcaptcha_agent.status.CHALLENGE_BACKCALL: - await self.page.wait_for_timeout(500) - fl = self.page.frame_locator(self.hcaptcha_agent.HOOK_CHALLENGE) - await fl.locator("//div[@class='refresh button']").click() - elif result == self.hcaptcha_agent.status.CHALLENGE_SUCCESS: - if self.hcaptcha_agent.cr: - captcha_token: str = self.hcaptcha_agent.cr.generated_pass_UUID - return captcha_token - - return f"Exceeded maximum retry times of {self.retry_times}" + await self.hcaptcha_agent.robotic_arm.click_checkbox() + # Wait for the challenge to appear and be ready for solving + # This may involve waiting for images to load or instructions to appear + result = await self.hcaptcha_agent.wait_for_challenge() + + if result == ChallengeSignal.SUCCESS: + if self.hcaptcha_agent.cr_list: + cr = self.hcaptcha_agent.cr_list[-1] + captcha_token: str = cr.generated_pass_UUID + return captcha_token + + return f"Failed HCaptcha solving with {result}" async def get_hcaptcha(self, site_key: Optional[str] = "00000000-0000-0000-0000-000000000000", rq_data: Optional[str] = None) -> Optional[str]: """ diff --git a/requirements.txt b/requirements.txt index 6165bd2..c76b258 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,11 +14,11 @@ numpy==1.26.4 # Artificial Intelligence -hcaptcha_challenger>=0.10.1.post2 +hcaptcha_challenger>=0.18.13 recognizer==1.4 # yolov5==7.0.13 # sentence_transformers #==2.2.2 # easyocr==1.7.1 # opencv-python~=4.9.0.80 setuptools~=69.5.1 -loguru==0.7.2 \ No newline at end of file +loguru==0.7.2 diff --git a/setup.cfg b/setup.cfg index 4f0ab24..f90d65e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = pybrowsers>=0.5.2 chrome-fingerprints numpy - hcaptcha_challenger>=0.10.1.post1 + hcaptcha_challenger>=0.11.0 recognizer setuptools loguru From 2dd8759d3cd4116592f690f0695e5910fb1cea96 Mon Sep 17 00:00:00 2001 From: Mynacol Date: Sun, 25 Jan 2026 21:25:00 +0000 Subject: [PATCH 2/2] Address review comments --- botright/modules/hcaptcha.py | 2 +- requirements.txt | 2 +- setup.cfg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/botright/modules/hcaptcha.py b/botright/modules/hcaptcha.py index e2de6bc..aaa8704 100644 --- a/botright/modules/hcaptcha.py +++ b/botright/modules/hcaptcha.py @@ -70,7 +70,7 @@ async def solve_hcaptcha(self, rq_data: Optional[str] = None) -> Optional[str]: captcha_token: str = cr.generated_pass_UUID return captcha_token - return f"Failed HCaptcha solving with {result}" + return None async def get_hcaptcha(self, site_key: Optional[str] = "00000000-0000-0000-0000-000000000000", rq_data: Optional[str] = None) -> Optional[str]: """ diff --git a/requirements.txt b/requirements.txt index c76b258..472e452 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,4 +21,4 @@ recognizer==1.4 # easyocr==1.7.1 # opencv-python~=4.9.0.80 setuptools~=69.5.1 -loguru==0.7.2 +loguru==0.7.3 diff --git a/setup.cfg b/setup.cfg index f90d65e..0383f10 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = pybrowsers>=0.5.2 chrome-fingerprints numpy - hcaptcha_challenger>=0.11.0 + hcaptcha_challenger>=0.18.13 recognizer setuptools loguru