Skip to content

About

SeleniumBase examples for solving reCAPTCHA, Cloudflare Turnstile, image, and coordinate captchas with Python.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Captcha Solver Selenium Python Examples

Captcha solving examples with Python and SeleniumBase

Examples of solving popular captcha types with captcha-solver-api, Selenium, and seleniumbase.

Each example shows how to:

  1. Open a page and collect captcha parameters.
  2. Send a task to Captcha Solver.
  3. Apply the solution in the browser.
  4. Check that the page accepted the solution.

Installation

Requirements:

  • Python 3.9 or newer
  • Google Chrome
  • A Captcha Solver API key with a positive balance
git clone https://github.com/captcha-solver-api/captcha-solver-selenium-python-examples.git
cd captcha-solver-selenium-python-examples
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
cp .env.example .env

On Windows:

.venv\Scripts\Activate.ps1
Copy-Item .env.example .env

Set your API key in .env:

CAPTCHA_API_KEY=your_api_key

Run

python examples/recaptcha_v2.py

The reCAPTCHA v2 example uses the official Google demo by default, and the Yandex SmartCaptcha example uses the official Yandex demo. Set TARGET_URL in .env to run another example against a page you are authorized to test.

Examples

Captcha File
reCAPTCHA v2 recaptcha_v2.py
reCAPTCHA v2 + proxy recaptcha_v2_proxy.py
reCAPTCHA v2 callback recaptcha_v2_callback_variant1.py
reCAPTCHA v2 callback, automatic discovery recaptcha_v2_callback_variant2.py
reCAPTCHA v2 callback + proxy recaptcha_v2_callback_proxy.py
reCAPTCHA v3 recaptcha_v3.py
reCAPTCHA v3 interception recaptcha_v3_extended_js_script.py
Cloudflare Turnstile cloudflare_turnstile.py
Cloudflare Challenge cloudflare_challenge_page.py
Tencent CAPTCHA tencent.py
Yandex SmartCaptcha yandex_smartcaptcha.py
Image captcha, screenshot normal_captcha_screenshot.py
Image captcha, canvas normal_captcha_canvas.py
Image captcha with parameters normal_captcha_screenshot_params.py
Coordinates coordinates.py

Yandex SmartCaptcha

After installation, set CAPTCHA_API_KEY in .env and run:

python examples/yandex_smartcaptcha.py

Leave TARGET_URL empty to use https://captcha-api.yandex.ru/demo. The example reads the widget's data-sitekey and the browser's User-Agent, requests a token using YandexSmartCaptchaTaskProxyless, fills smart-token, and submits the form. It reports success only after the page returns Hello, user!.

The example uses the same .env configuration, shared API client, and console logging as the other examples. Running it creates a paid solving task.

To adapt it to a page you are authorized to test, set TARGET_URL and update SITEKEY_SELECTOR, SUBMIT_LOCATOR, and the success check in the script. If your application uses a callback instead of reading smart-token, adapt the token delivery to that callback as well.

Tencent CAPTCHA

Tencent requires your own target page and selectors:

TARGET_URL=https://your-site.example/tencent-captcha
TENCENT_TRIGGER_SELECTOR=#open-captcha
TENCENT_SUCCESS_SELECTOR=.verification-success

Leave TENCENT_TRIGGER_SELECTOR empty if the page opens the captcha automatically.

Proxy

PROXY_TYPE=http
PROXY_ADDRESS=proxy.example.com
PROXY_PORT=8080
PROXY_LOGIN=
PROXY_PASSWORD=

The browser and API task use the same proxy.

Checks

python -m pip install ruff
ruff check .
ruff format --check .

Documentation

License

MIT

About

SeleniumBase examples for solving reCAPTCHA, Cloudflare Turnstile, image, and coordinate captchas with Python.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors