Asynchronous Python solution for bypassing Cloudflare's anti-bot challenges, supporting both Challenge (cookie-based) and Turnstile (token-based) types.
- Dual Challenge Support - Handles both Challenge (
cf_clearancecookie) and Turnstile (token) types - Asynchronous - Built with
asyncioandPlaywrightfor high performance - Stealthy - Uses Camoufox and BrowserForge for realistic browser fingerprinting
- Modular - Clean OOP design with dataclasses for results handling
- Configurable - Customize retries, delays, OS fingerprint, and more
- Logging - Built-in debug logging for troubleshooting
- Install the package dependencies:
pip install -r requirements.txt- Install Playwright browsers:
playwright installfrom main import CloudflareSolver, ChallengeType
import asyncio
async def main():
solver = CloudflareSolver(
challenge_type=ChallengeType.CHALLENGE,
headless=True,
os=["windows"],
)
result = await solver.solve("https://nopecha.com/demo/cloudflare")
if result:
print(f"Cookie obtained: {result.name}={result.value}")
else:
print("Failed to solve Cloudflare challenge")
asyncio.run(main())from main import CloudflareSolver, ChallengeType
import asyncio
async def main():
solver = CloudflareSolver(
challenge_type=ChallengeType.TURNSTILE,
headless=True,
os=["windows"],
)
result = await solver.solve("https://nopecha.com/captcha/turnstile")
if result:
print(f"Token obtained: {result.token}")
else:
print("Failed to solve Turnstile challenge")
asyncio.run(main())solver = CloudflareSolver(
challenge_type=ChallengeType.TURNSTILE, # or ChallengeType.CHALLENGE
sleep_time=5, # Longer delay before clicking challenge
headless=False, # Show browser window
os=["macos"], # macOS fingerprint
debug=True, # Enable verbose logging
retries=50 # More attempts to find challenge
)Defines the type of Cloudflare challenge to solve:
CHALLENGE- Traditional challenge that returnscf_clearancecookieTURNSTILE- Turnstile challenge that returns a token from hidden input field
Represents the Cloudflare clearance cookie (for Challenge type):
name: Cookie name (typically "cf_clearance")value: Cookie valuedomain: Cookie domainpath: Cookie pathexpires: Expiration timestamphttp_only: HTTP Only flagsecure: Secure flagsame_site: SameSite policy
Represents the Turnstile token (for Turnstile type):
token: Token value extracted fromcf-turnstile-responseinput field
challenge_type: Type of challenge to solve -ChallengeType.CHALLENGEorChallengeType.TURNSTILE(default:ChallengeType.CHALLENGE)sleep_time: Delay before clicking challenge (default: 3)headless: Run browser in headless mode (default: True)os: OS fingerprint (default: ["windows"])debug: Enable debug logging (default: False)retries: Number of attempts to find challenge (default: 30)
solve(link: str): Solves Cloudflare challenge for given URL, returnsCloudflareCookie,TurnstileToken, orNone
- Launches a stealthy browser instance with realistic fingerprint
- Navigates to the protected URL
- Detects Cloudflare challenge iframe
- Automatically clicks the verification checkbox
- Extracts the
cf_clearancecookie upon success - Returns the cookie as a validated dataclass object
- Launches a stealthy browser instance with realistic fingerprint
- Navigates to the protected URL
- Detects Cloudflare challenge iframe
- Automatically clicks the verification checkbox
- Extracts the token from
cf-turnstile-responsehidden input field - Returns the token as a validated dataclass object
Important
By using this repository or any code related to it, you agree to the legal notice. The author is not responsible for the usage of this repository nor endorses it, nor is the author responsible for any copies, forks, re-uploads made by other users, or anything else related to this repository.