Anti-Cloudflare Task
This task type is used to solve Cloudflare's JavaScript Challenge (the 'Checking your browser...' interstitial page). The solution provides a valid `cf_clearance` cookie.
How to Use the Solution
You must use the `userAgent` and `cookies` (specifically `cf_clearance`) from the solution in your subsequent requests to the target website.
Proxy is Required
This task type requires a proxy. The proxy's IP should ideally be in the same region as the target website's server for the best success rate.
1. Create Task
Use the `createTask` method to initiate the solving process. You must provide the `websiteURL` and a `proxy`.
Task Object Parameters
| Property | Type | Required | Description |
|---|---|---|---|
| type | String | Required | Must be `AntiCloudflareTask` |
| websiteURL | String | Required | The full URL of the page protected by a Cloudflare JS Challenge. |
| proxy | String | Required | Your proxy address in the format `http:login:password@ip:port`. |
Run Sandbox Task
2. Get Result
After creating a task, use the `getTaskResult` method to check the status and retrieve the solution. Poll this endpoint every 5-10 seconds until the status is `completed`.
Fetch Result Sandbox
SDK Usage
# Coming soon: A simplified Python SDK
# pip install --upgrade captchasonic
#
# from captchasonic import CaptchaSonic
#
# client = CaptchaSonic(api_key="YOUR_API_KEY")
#
# solution = client.solve_cloudflare(
# website_url="https://www.g2.com/products/discord/reviews",
# proxy="http:login:[email protected]:8888"
# )
# print(f"CF Clearance Cookie: {solution.cookies['cf_clearance']}")Full Sample Code
import requests
import time
API_KEY = "YOUR_API_KEY"
API_URL = "https://api.captchasonic.com"
def solve_cloudflare():
# 1. Create the task
print("Creating Cloudflare task...")
create_payload = {
"apiKey": API_KEY,
"task": {
"type": "AntiCloudflareTask",
"websiteURL": "https://www.g2.com/products/discord/reviews",
"proxy": "http:login:[email protected]:8888"
}
}
res = requests.post(f"{API_URL}/createTask", json=create_payload)
if res.status_code != 200:
print(f"Error creating task: {res.text}")
return
task_id = res.json().get("taskId")
if not task_id:
print(f"Could not find taskId in response: {res.json()}")
return
print(f"Task created successfully. Task ID: {task_id}")
# 2. Poll for the result
while True:
print("Polling for result...")
time.sleep(5) # Wait 5 seconds between polls
get_payload = {"apiKey": API_KEY, "taskId": task_id}
res = requests.post(f"{API_URL}/getTaskResult", json=get_payload)
if res.status_code != 200:
print(f"Error getting result: {res.text}")
continue
resp_json = res.json()
status = resp_json.get("status")
if status == "completed":
print("Task completed!")
return resp_json.get("solution")
elif status == "failed":
print(f"Task failed: {resp_json.get('errorDescription')}")
return
elif status == "processing":
print("Task is still processing, trying again...")
else:
print(f"Unknown status: {status}, response: {resp_json}")
# Run the solver
solution = solve_cloudflare()
if solution:
print("\n--- SOLUTION ---")
print(f"User-Agent: {solution.get('userAgent')}")
print(f"cf_clearance: {solution.get('cookies', {}).get('cf_clearance')}")
print("----------------")