Cloudflare: solving Challenge (5s)
Create the task with the createTask method and get the result with the getTaskResult method.
ℹ️ This task type require your own proxies.
Please note that the Cloudflare challenge service is currently under maintenance and only supports the Cloudflare Turnstile service at this time. If you have any customization needs, please feel free to contact us via Livechat or Email.
The Turnstile/Challenge captcha is another attempt to replace reCaptcha/hCaptcha. We automatically support these subtypes:
- turnstile
- Manually
- Non-Interactive
- InVisible
- challenge
- 5s challenge
- Non-Interactive turnstile
There is no need to specify subtypes during your call. It is not necessary to provide your own custom User-Agent
yet,
we will ignore this parameter.
Type | Note | State |
---|---|---|
challenge | stable | |
challenge + turnstile | stable |
The task type type
is as follows
AntiCloudflareTask
Proxy required
Create Task
Create the task with the createTask.
In the process of using challenge, we must input websiteURL
,proxy
other parameters are optional.
Task Object Structure
Properties | Type | Required | Description |
---|---|---|---|
type | String | Required | AntiCloudflareTask |
websiteURL | String | Required | The address of the target page. |
proxy | String | Required | Learn using proxies |
Example request
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "158.120.100.23:334:user:pass"
}
}
Example Response
{
"errorId": 0,
"status": "idle",
"taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006" // record taskId
}
Getting Result
Use the getTaskResult method to get the recognition results
Depending on the system load, you will get the results within the interval of 1s
to 20s
Example Request
POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}
Example Response
{
"errorId": 0,
"taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006",
"status": "ready",
"solution": {
"cookies": {
"cf_clearance": "..."
},
"proxy": "...",
"token": "...",
"type": "challenge",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
}
Use SDK Request
# pip install --upgrade capsolver
# export CAPSOLVER_API_KEY='...'
import capsolver
# capsolver.api_key = "..."
solution = capsolver.solve({
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "158.120.100.23:334:user:pass"
})
Sample Code
# pip install requests
# pip install tls-client
import tls_client
import requests
import time
api_key = "your api key of capsolver"
page_url = "Your target site url"
proxy = "http://name:pass@host:port"
def capsolver():
payload = {
"clientKey": api_key,
"task": {
"type": "AntiCloudflareTask",
"websiteURL": page_url,
"proxy": proxy
}
}
res = requests.post("https://api.capsolver.com/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"Got taskId: {task_id} / Getting result...")
while True:
time.sleep(1) # delay
payload = {"clientKey": api_key, "taskId": task_id}
res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
return resp.get("solution", {})
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
def request_site(solution):
session = tls_client.Session(
client_identifier="chrome_120",
random_tls_extension_order=True
)
return session.get(
page_url,
headers=solution.get('headers'),
cookies=solution.get('cookies'),
proxy=proxy,
)
def main():
solution = capsolver()
if not solution:
return
res = request_site(solution)
print('response status code:', res.status_code)
if __name__ == '__main__':
main()