from curl_cffi import requests
import time
# 创建任务
def create_task(url, proxy):
data = {
# 填您自己的密钥
"clientKey": clientKey,
"task": {
"type": "CloudFlareTaskS1CloudFlareTaskS2",
"websiteURL": url,
"proxy": proxy
}
}
url = "https://api.yescaptcha.com/createTask"
response = requests.post(url, json=data).json()
return response
# 获取结果
def get_task(task_id):
url = "http://api.yescaptcha.com/getTaskResult"
data = {
# 填您自己的密钥
"clientKey": clientKey,
"taskId": task_id
}
response = requests.post(url, json=data).json()
return response
# 完整的请求
def get_result(*args, **kwargs):
uuid = create_task(*args, **kwargs)
if not uuid or not uuid.get('taskId'):
return uuid
print("TaskID:", uuid)
for i in range(30):
time.sleep(3)
result = get_task(uuid.get('taskId'))
if result.get('status') == 'processing':
continue
elif result.get('status') == 'ready':
return result
else:
print("Fail:", result)
if __name__ == '__main__':
# 填您的密钥
clientKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# 填您自己的代理,不要填本地的地址
proxy = "http://JN3wWChA:Dsg7ckfv@176.222.59.86:64048"
proxies = {
'http': proxy,
'https': proxy,
}
# 要访问的网址
url = "https://nowsecure.nl"
# 正常情况是这样的
# response = requests.get(url, proxies=proxies)
# print("请求响应:", response.status_code)
# print("网页标题:", response.text[:200])
# 返回:请求响应: 403
# 使用 curl_cffi.requests请求
# response = requests.get(url, proxies=proxies, impersonate="chrome110")
# print("请求响应:", response.status_code)
# print("网页标题:", response.text[:200])
# 返回:请求响应: 200
# 使用接口返回的值来请求
task = get_result(url, proxy=proxy)
if not task.get("solution"):
print("任务失败", task)
exit()
solution = task.get("solution")
headers = {
'User-Agent': solution.get("user_agent")
}
print("Ua", headers)
cookies = solution.get("cookies")
print("Cookies:", cookies)
response = requests.get(url, headers=headers, cookies=cookies, proxies=proxies, impersonate="chrome110")
print("请求响应:", response.status_code)
print("网页标题:", response.text[:200]) |