Cloudflare: memecahkan Tantangan
TIP
Buat tugas dengan metode createTask dan dapatkan hasilnya dengan metode getTaskResult.
Note
- Proksi sangat diperlukan, harap gunakan proksi Statis atau proksi Sticky, bukan proksi Rotating.
- Mendukung userAgent kustom, harap jaga agar tetap sama dengan yang Anda gunakan.
- Jika Anda gagal mendapatkan solusi, IP Anda mungkin diblokir, harap coba ubah proksi Anda.
- Anda harus menggunakan pustaka permintaan TLS untuk meminta situs web target.
Tipe tugas type adalah sebagai berikut
AntiCloudflareTask
Buat Tugas
Buat tugas dengan createTask.
Struktur Objek Tugas
| Properties | Type | Required | Description |
|---|---|---|---|
| type | String | Required | AntiCloudflareTask |
| websiteURL | String | Required | Alamat halaman target. |
| proxy | String | Required | Proksi Statis atau Sticky Anda. Pelajari Menggunakan proksi |
| userAgent | String | Optional | user-agent yang Anda gunakan untuk meminta situs web target. Hanya userAgent Chrome yang didukung |
| html | String | Optional | Respon dari permintaan ke situs web target, biasanya berisi “Just a moment…” dan kode status 403. Beberapa situs web memerlukan HTML. |
Contoh Permintaan
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",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
"html": "<!DOCTYPE html><html lang=\"en-US\"><head><title>Just a moment...</title>...",
"proxy": "ip:port:user:pass"
}
}Contoh Respon
{
"errorId": 0,
"status": "idle",
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca"
}
Mendapatkan Hasil
Gunakan metode getTaskResult untuk mendapatkan hasil pengenalan
Tergantung pada situs web dan proksi, Anda akan mendapatkan hasilnya dalam interval 2s hingga 20s
Contoh Permintaan
POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json{
"clientKey": "YOUR_API_KEY",
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca"
}Contoh Respon
{
"errorId": 0,
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca",
"status": "ready",
"errorCode": "",
"errorDescription": "",
"solution": {
"cookies": {
"cf_clearance": "Bcg6jNLzTVaa3IsFhtDI.e4_LX8p7q7zFYHF7wiHPo...uya1bbdfwBEi3tNNQpc"
},
"token": "Bcg6jNLzTVaa3IsFhtDI.e4_LX8p7q7zFYHF7wiHPo...uya1bbdfwBEi3tNNQpc",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
}
}Gunakan Permintaan SDK
# pip install --upgrade capsolver
# export CAPSOLVER_API_KEY='...'
import capsolver
# capsolver.api_key = "..."
solution = capsolver.solve({
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "ip:port:user:pass"
})Contoh Kode
# pip install requests
import requests
import time
api_key = "YOUR_API_KEY" # your api key of capsolver
def capsolver():
payload = {
"clientKey": api_key,
"task": {
"type": "AntiCloudflareTask",
"websiteURL": "https://www.yourwebsite.com",
"proxy": "ip:port:user:pass"
}
}
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
token = capsolver()
print(token)