forked from Zakkoree/woiden_extend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyescaptchaAPI.py
112 lines (97 loc) · 3.52 KB
/
yescaptchaAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
author: Zakkoree
"""
import time
import requests
from commonlog import Logger
logger = Logger(LoggerName="yescaptchaAPI")
def create_task(clientKey: str, websiteKey: str, websiteURL: str) -> str:
data = {
"clientKey": clientKey,
"task": {
"websiteURL": websiteURL,
"websiteKey": websiteKey,
"type": "NoCaptchaTaskProxyless"
}
}
return create(data)
def create(data):
try:
url = "https://api.yescaptcha.com/createTask"
requests.packages.urllib3.disable_warnings()
return requests.post(url, json=data, verify=False).json()
except Exception as e:
logger.error(e)
return None
def create_task_v3(clientKey: str, websiteKey: str, websiteURL: str, pageAction: str) -> str:
data = {
"clientKey": clientKey,
"task": {
"websiteURL": websiteURL,
"websiteKey": websiteKey,
"pageAction" : pageAction,
"type": "RecaptchaV3TaskProxyless"
}
}
return create(data)
def get_response(taskID: str, clientKey: str):
times = 0
while times < 60:
try:
url = f"https://api.yescaptcha.com/getTaskResult"
data = {
"clientKey": clientKey,
"taskId": taskID
}
requests.packages.urllib3.disable_warnings()
result = requests.post(url, json=data, verify=False).json()
solution = result.get('solution', {})
if solution:
response = solution.get('gRecaptchaResponse')
if response:
return response
if result.get('errorId') == 1:
return None
except Exception as e:
logger.error(e)
times += 3
time.sleep(3)
logger.error("yescaptcha get_response timeout")
return None
def verify_website(response, websiteURL):
data = {"g-recaptcha-response": response}
r = requests.post(websiteURL, data=data)
if r.status_code == 200:
return r.text
def asr(clientKey: str, websiteKey: str, websiteURL: str, task_type: str):
taskResult = create_task(clientKey, websiteKey, websiteURL, task_type)
taskId = taskResult.get('taskId')
if taskId is not None:
response = get_response(taskId, clientKey)
logger.info("yescaptcha :" + response)
return response
# result = verify_website(response)
# print('验证结果:', result)
else:
logger.error("yescaptcha create_task :" + taskResult.get('errorDescription'))
return None
def asrV3(clientKey: str, websiteKey: str, websiteURL: str, pageAction: str):
taskResult = create_task_v3(clientKey, websiteKey, websiteURL, pageAction)
taskId = taskResult.get('taskId')
if taskId is not None:
response = get_response(taskId, clientKey)
logger.info("yescaptcha V3 :" + response)
return response
# result = verify_website(response, websiteURL)
# print('验证结果:', result)
else:
logger.error("yescaptcha V3 create_task :" + taskResult.get('errorDescription'))
return None
if __name__ == '__main__':
# clientKey:在个人中心获取
clientKey = "xxxxxxxx"
# 目标参数:
websiteKey = "6LdZ3_YZAAAAALyzLQjyjE6RPFdcG9A-TLr6AxF0"
# 目标参数:
websiteURL = "https://woiden.id"
asr(clientKey, websiteKey, websiteURL)