Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions botright/botright.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 15 additions & 19 deletions botright/modules/hcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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 None

async def get_hcaptcha(self, site_key: Optional[str] = "00000000-0000-0000-0000-000000000000", rq_data: Optional[str] = None) -> Optional[str]:
"""
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
loguru==0.7.3
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
pybrowsers>=0.5.2
chrome-fingerprints
numpy
hcaptcha_challenger>=0.10.1.post1
hcaptcha_challenger>=0.18.13
recognizer
setuptools
loguru
Expand Down