Examples of solving popular captcha types with
captcha-solver-api,
Selenium, and
seleniumbase.
Each example shows how to:
- Open a page and collect captcha parameters.
- Send a task to Captcha Solver.
- Apply the solution in the browser.
- Check that the page accepted the solution.
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 .envOn Windows:
.venv\Scripts\Activate.ps1
Copy-Item .env.example .envSet your API key in .env:
CAPTCHA_API_KEY=your_api_keypython examples/recaptcha_v2.pyThe 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.
| 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 |
After installation, set CAPTCHA_API_KEY in .env and run:
python examples/yandex_smartcaptcha.pyLeave 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 requires your own target page and selectors:
TARGET_URL=https://your-site.example/tencent-captcha
TENCENT_TRIGGER_SELECTOR=#open-captcha
TENCENT_SUCCESS_SELECTOR=.verification-successLeave TENCENT_TRIGGER_SELECTOR empty if the page opens the captcha
automatically.
PROXY_TYPE=http
PROXY_ADDRESS=proxy.example.com
PROXY_PORT=8080
PROXY_LOGIN=
PROXY_PASSWORD=The browser and API task use the same proxy.
python -m pip install ruff
ruff check .
ruff format --check .