Skip to content
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
20 changes: 18 additions & 2 deletions examples/common.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand Down
Loading