Get past a Cloudflare Turnstile challenge once, then scrape with curl_cffi.
Note: intended for accessing sites you are allowed to access programmatically.
# uv
uv add cfts-solver
# pip
pip install cfts-solverYou also need Google Chrome or Chromium on the host. It runs once per host, to clear the challenge; every request after that is plain HTTP.
import cfts_solver
from curl_cffi import requests
URL = "https://example.com/"
session = requests.Session(impersonate="chrome")
res = session.get(URL)
if cfts_solver.is_challenged(res.headers, res.text):
clearance = cfts_solver.solve_challenge(URL)
clearance.apply(session) # cookies plus the user agent that earned them
res = session.get(URL)
print(res.status_code, len(res.text))from cfts_solver import TurnstileSession
with TurnstileSession() as session:
res = session.get("https://example.com/")
print(res.status_code)from cfts_solver import TurnstileSolver
solver = TurnstileSolver()
clearance = solver.solve("https://example.com/")
refreshed = solver.solve("https://example.com/", refresh=True)
print(clearance.token, clearance.user_agent)Clearances are cached under $XDG_CACHE_HOME/cfts-solver/, keyed by host
and proxy, so a second process does not start a second browser. Pass
ClearanceStore.in_memory() to keep nothing, or ClearanceStore(path) to keep
it somewhere else.