diff --git a/README.md b/README.md index 8a12b41..0a774b8 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ python examples/recaptcha_v2.py Chrome stays visible so you can observe parameter extraction, solution delivery, and submission on the page. +After the API returns a solution, every example prints the complete solution as +formatted JSON, including the token or recognized answer and any additional +response fields. The page's success message is printed after the solution has +been applied, so the console records both the API response and page verification. +The API key is never printed. + ## Available examples | Captcha type | Example | What it demonstrates | diff --git a/examples/common.py b/examples/common.py index 805a369..4c4db33 100644 --- a/examples/common.py +++ b/examples/common.py @@ -1,7 +1,8 @@ """Shared helpers for the Selenium examples.""" +import json import os -from typing import Dict +from typing import Any, Dict, Optional from captcha_solver_api import CaptchaClient from dotenv import load_dotenv @@ -12,6 +13,21 @@ load_dotenv() +class ConsoleCaptchaClient(CaptchaClient): + """Captcha client that prints the complete solution returned by the API.""" + + def solve( + self, + task: Any, + language_pool: Optional[str] = None, + timeout: Optional[int] = None, + ) -> Dict[str, Any]: + solution = super().solve(task, language_pool=language_pool, timeout=timeout) + print("API response:") + print(json.dumps(solution, ensure_ascii=False, indent=2, sort_keys=True)) + return solution + + def required_env(name: str) -> str: value = os.getenv(name) if not value: @@ -20,7 +36,7 @@ def required_env(name: str) -> str: def create_client() -> CaptchaClient: - return CaptchaClient(required_env("CAPTCHA_API_KEY")) + return ConsoleCaptchaClient(required_env("CAPTCHA_API_KEY")) def wait_for_css(driver, selector: str, timeout: int = 30):