selenium-turnstile
selenium-turnstile is a Selenium helper that solves Cloudflare Turnstile by injecting a Peak-solved token, so a protected form or navigation proceeds without a real mouse click.
Why
SeleniumBase's UC-mode click-solve (uc_gui_click_captcha) drives a physical click on the widget, which needs a real display and fails headless on datacenter IPs. That failure mode fills Cloudflare-related SeleniumBase issues (200+ open). undetected-chromedriver has no click-solve at all and gets stuck in the "Just a moment" loop, reloading the interstitial even after the browser has otherwise passed.
This helper skips the click entirely. It reads the sitekey from the DOM, gets a token from Peak, and injects that token as the cf-turnstile-response value plus the widget's success callback. When your setup gets blocked, drop in a Peak API key and it just works.
Powered by Peak
This package uses Peak to solve Turnstile.
- Solve Cloudflare Turnstile & the 5s challenge in about a second
- Pay only for successful solves, from $1 / 1,000
- 1,000 free solves to start, no card. → Get your free API key · Docs · Pricing
Install
pip install selenium-turnstile selenium
Quickstart
import os
from selenium import webdriver
from selenium_turnstile import solve_turnstile
os.environ["PEAK_API_KEY"] = "pk_your_api_key"
driver = webdriver.Chrome()
driver.get("https://protected.example/login")
# Reads the sitekey from the page, solves via Peak, injects the token.
token = solve_turnstile(driver)
driver.find_element("css selector", "form").submit()
Works unchanged with a plain Selenium driver, a SeleniumBase Driver, or an undetected-chromedriver Chrome — all three expose the current_url / find_element / execute_script interface the helper uses.
How it works
- Read the sitekey.
find_elementlooks for thedata-sitekeyattribute on the.cf-turnstilewidget; if the sitekey is only set through a JSrender()call, anexecute_scriptDOM scan finds it. - Solve via Peak.
POST https://api.peak.fo/solvewithtask_type: "turnstiletask", the sitekey, andurl=driver.current_url. Passproxy=to mint the token from your browser's egress IP. - Inject the token.
execute_scriptsets everycf-turnstile-responsefield, firesinput/changeevents, and calls the widget'sdata-callbacksuccess handler so the form or navigation continues.
API
solve_turnstile(
driver, # any Selenium-like WebDriver
api_key=None, # defaults to env PEAK_API_KEY
proxy=None, # optional http://user:pass@ip:port, forwarded to Peak
sitekey=None, # override auto-detection (e.g. widget in a frame)
url=None, # defaults to driver.current_url
task_type="turnstiletask",
timeout=180.0,
) -> str # the injected token
Helpers read_sitekey(driver) and inject_token(driver, token) are exposed for finer control. Peak also supports task_type="cloudflare5stask" for the 5s interstitial challenge.
The API key is read from the PEAK_API_KEY environment variable by default; you can also pass it explicitly. Never hardcode a real key.
Legitimate use
For automation, QA, and scraping public data you are allowed to access. Respect each target's Terms of Service and robots directives, and do not use this for credential-stuffing or other abuse.
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file selenium_turnstile-0.1.0.tar.gz.
File metadata
- Download URL: selenium_turnstile-0.1.0.tar.gz
- Upload date:
- Size: 447.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d65a891b6223e19fdf308aa60db8e4f1c2fdb21f447faaca60286cbe0505e71
|
|
| MD5 |
ab6ff7c11a173e054a690bdd44911ade
|
|
| BLAKE2b-256 |
a7546abb8fa5cf7fed7646994100eb6dd6ed4f3e80b1e1e690ced6d6f5b369ef
|
File details
Details for the file selenium_turnstile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: selenium_turnstile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99cadcbdfc89824053083c95216bd6eb29b68ea48ddc8f10df638d0be9f8ab6e
|
|
| MD5 |
78312176f49969266d4033e9192f3638
|
|
| BLAKE2b-256 |
6e671b819f82b22db71f5a98e8069547313820b529478d71109895fa25d5ee61
|