Cloudflare: चुनौती का समाधान
TIP
createTask विधि का उपयोग करके कार्य बनाएं और getTaskResult विधि से परिणाम प्राप्त करें।
Note
- प्रॉक्सी आवश्यक है, कृपया Rotating proxy के बजाय Static proxy या Sticky proxy का उपयोग करें।
- कस्टम userAgent का समर्थन करता है, कृपया इसे उसी के समान रखें जिसका आप उपयोग कर रहे हैं।
- यदि आप समाधान प्राप्त करने में विफल रहते हैं, तो आपका IP ब्लॉक हो सकता है, कृपया अपना प्रॉक्सी बदलने का प्रयास करें।
- आपको लक्ष्य वेबसाइट का अनुरोध करने के लिए TLS रिक्वेस्ट लाइब्रेरी का उपयोग करना होगा।
कार्य प्रकार type
इस प्रकार है
AntiCloudflareTask
कार्य बनाएं
createTask का उपयोग करके कार्य बनाएं।
कार्य ऑब्जेक्ट संरचना
गुणधर्म | प्रकार | आवश्यक | विवरण |
---|---|---|---|
type | String | आवश्यक | AntiCloudflareTask |
websiteURL | String | आवश्यक | लक्ष्य पृष्ठ का पता। |
proxy | String | आवश्यक | आपका Static proxy या Sticky proxy। प्रॉक्सी का उपयोग कैसे करें जानें |
userAgent | String | वैकल्पिक | लक्ष्य वेबसाइट का अनुरोध करने के लिए आपके द्वारा उपयोग किया गया user-agent । केवल Chrome के userAgent का समर्थन है |
उदाहरण अनुरोध
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",
"proxy": "ip:port:user:pass"
}
}
उदाहरण प्रतिक्रिया
{
"errorId": 0,
"status": "idle",
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca"
}
परिणाम प्राप्त करना
पहचान परिणाम प्राप्त करने के लिए getTaskResult विधि का उपयोग करें
वेबसाइट और प्रॉक्सी के आधार पर, आपको 2s
से 20s
के अंतराल के भीतर परिणाम मिलेंगे
उदाहरण अनुरोध
POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"taskId": "df944101-64ac-468d-bc9f-41baecc3b8ca"
}
उदाहरण प्रतिक्रिया
{
"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"
}
}
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"
})
नमूना कोड
# 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)