python-rucaptcha 6.1__0-py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_rucaptcha/__init__.py +0 -0
- python_rucaptcha/__version__.py +1 -0
- python_rucaptcha/amazon_waf.py +114 -0
- python_rucaptcha/audio_captcha.py +161 -0
- python_rucaptcha/bounding_box_captcha.py +310 -0
- python_rucaptcha/capy_puzzle.py +138 -0
- python_rucaptcha/control.py +174 -0
- python_rucaptcha/coordinates_captcha.py +295 -0
- python_rucaptcha/core/__init__.py +0 -0
- python_rucaptcha/core/base.py +244 -0
- python_rucaptcha/core/config.py +21 -0
- python_rucaptcha/core/enums.py +146 -0
- python_rucaptcha/core/result_handler.py +65 -0
- python_rucaptcha/core/serializer.py +74 -0
- python_rucaptcha/cutcaptcha.py +116 -0
- python_rucaptcha/cyber_siara_captcha.py +110 -0
- python_rucaptcha/datadome_captcha.py +121 -0
- python_rucaptcha/draw_around_captcha.py +359 -0
- python_rucaptcha/fun_captcha.py +103 -0
- python_rucaptcha/gee_test.py +216 -0
- python_rucaptcha/grid_captcha.py +271 -0
- python_rucaptcha/hcaptcha.py +111 -0
- python_rucaptcha/image_captcha.py +249 -0
- python_rucaptcha/key_captcha.py +111 -0
- python_rucaptcha/lemin_captcha.py +112 -0
- python_rucaptcha/mt_captcha.py +104 -0
- python_rucaptcha/re_captcha.py +172 -0
- python_rucaptcha/rotate_captcha.py +196 -0
- python_rucaptcha/text_captcha.py +119 -0
- python_rucaptcha/turnstile.py +111 -0
- python_rucaptcha-6.1.0.dist-info/METADATA +138 -0
- python_rucaptcha-6.1.0.dist-info/RECORD +34 -0
- python_rucaptcha-6.1.0.dist-info/WHEEL +5 -0
- python_rucaptcha-6.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from .core.base import BaseCaptcha
|
|
4
|
+
from .core.enums import GeetestEnm
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GeeTest(BaseCaptcha):
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
websiteURL: str,
|
|
11
|
+
method: Union[GeetestEnm, str],
|
|
12
|
+
gt: str,
|
|
13
|
+
version: int = 3,
|
|
14
|
+
initParameters: dict = None,
|
|
15
|
+
*args,
|
|
16
|
+
**kwargs,
|
|
17
|
+
):
|
|
18
|
+
"""
|
|
19
|
+
The class is used to work with GeeTest.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
rucaptcha_key: User API key
|
|
23
|
+
websiteURL: Full URL of the captcha page
|
|
24
|
+
gt: The value of the `gt` parameter found on the site
|
|
25
|
+
version: GeeTest V4 captcha should be set to 4.
|
|
26
|
+
initParameters: Required for GeeTest V4. The parameter that is passed in the initGeetest4 function call must contain the captcha_id value.
|
|
27
|
+
Example of usage: { "captcha_id" : "e392e1d7fd421dc63325744d5a2b9c73"}
|
|
28
|
+
method: Captcha type
|
|
29
|
+
kwargs: Not required params for task creation request
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
>>> import requests
|
|
33
|
+
>>> resp_data = requests.get("https://www.geetest.com/demo/gt/register-enFullpage-official").json()
|
|
34
|
+
>>> print(resp_data)
|
|
35
|
+
{
|
|
36
|
+
'success': 1,
|
|
37
|
+
'challenge': '1ad03db8aff920037fb8117827eab171',
|
|
38
|
+
'gt': '022397c99c9f646f6477822485f30404',
|
|
39
|
+
'new_captcha': True
|
|
40
|
+
}
|
|
41
|
+
>>> GeeTest(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
42
|
+
... gt=resp_data["gt"],
|
|
43
|
+
... websiteURL="https://www.geetest.com/en/demo",
|
|
44
|
+
... method=GeetestEnm.GeeTestTaskProxyless.value
|
|
45
|
+
... ).captcha_handler(challenge=resp_data["challenge"])
|
|
46
|
+
{
|
|
47
|
+
"errorId":0,
|
|
48
|
+
"status":"ready",
|
|
49
|
+
"solution":{
|
|
50
|
+
"captcha_id":"e392e1d7fd421dc63325744d5a2b9c73",
|
|
51
|
+
"lot_number":"e6c3bed2854f41f880662c48afff5dcb",
|
|
52
|
+
"pass_token":"fad5eb52fc83bf7617402fcccfb211a21e0aa1d1044",
|
|
53
|
+
"gen_time":"1693924478",
|
|
54
|
+
"captcha_output":"fN36ufW6cQN4SQ-JRDQC70nSq9UcQBg=="
|
|
55
|
+
},
|
|
56
|
+
"cost":"0.00299",
|
|
57
|
+
"ip":"1.2.3.4",
|
|
58
|
+
"createTime":1692863536,
|
|
59
|
+
"endTime":1692863556,
|
|
60
|
+
"solveCount":1,
|
|
61
|
+
"taskId":75190409731
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
>>> await GeeTest(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
65
|
+
... gt=resp_data["gt"],
|
|
66
|
+
... websiteURL="https://www.geetest.com/en/demo",
|
|
67
|
+
... method=GeetestEnm.GeeTestTaskProxyless.value
|
|
68
|
+
... ).aio_captcha_handler(challenge=resp_data["challenge"])
|
|
69
|
+
{
|
|
70
|
+
"errorId":0,
|
|
71
|
+
"status":"ready",
|
|
72
|
+
"solution":{
|
|
73
|
+
"captcha_id":"e392e1d7fd421dc63325744d5a2b9c73",
|
|
74
|
+
"lot_number":"e6c3bed2854f41f880662c48afff5dcb",
|
|
75
|
+
"pass_token":"fad5eb52fc83bf7617402fcccfb211a21e0aa1d1044",
|
|
76
|
+
"gen_time":"1693924478",
|
|
77
|
+
"captcha_output":"fN36ufW6cQN4SQ-JRDQC70nSq9UcQBg=="
|
|
78
|
+
},
|
|
79
|
+
"cost":"0.00299",
|
|
80
|
+
"ip":"1.2.3.4",
|
|
81
|
+
"createTime":1692863536,
|
|
82
|
+
"endTime":1692863556,
|
|
83
|
+
"solveCount":1,
|
|
84
|
+
"taskId":75190409731
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
>>> GeeTest(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
88
|
+
... websiteURL="https://rucaptcha.com/demo/geetest-v4",
|
|
89
|
+
... method=GeetestEnm.GeeTestTaskProxyless.value,
|
|
90
|
+
... version=4,
|
|
91
|
+
... initParameters={"captcha_id": "e392e1d7fd421dc63325744d5a2b9c73"},
|
|
92
|
+
... ).captcha_handler(challenge=resp_data["challenge"])
|
|
93
|
+
{
|
|
94
|
+
"errorId":0,
|
|
95
|
+
"status":"ready",
|
|
96
|
+
"solution":{
|
|
97
|
+
"captcha_id":"e392e1d7fd421dc63325744d5a2b9c73",
|
|
98
|
+
"lot_number":"e6c3bed2854f41f880662c48afff5dcb",
|
|
99
|
+
"pass_token":"fad5eb52fc83bf7617402fcccfb211a21e0aa1d1044",
|
|
100
|
+
"gen_time":"1693924478",
|
|
101
|
+
"captcha_output":"fN36ufW6cQN4SQ-JRDQC70nSq9UcQBg=="
|
|
102
|
+
},
|
|
103
|
+
"cost":"0.00299",
|
|
104
|
+
"ip":"1.2.3.4",
|
|
105
|
+
"createTime":1692863536,
|
|
106
|
+
"endTime":1692863556,
|
|
107
|
+
"solveCount":1,
|
|
108
|
+
"taskId":75190409731
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
>>> await GeeTest(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
112
|
+
... websiteURL="https://rucaptcha.com/demo/geetest-v4",
|
|
113
|
+
... method=GeetestEnm.GeeTestTaskProxyless.value,
|
|
114
|
+
... version=4,
|
|
115
|
+
... initParameters={"captcha_id": "e392e1d7fd421dc63325744d5a2b9c73"},
|
|
116
|
+
... ).aio_captcha_handler(challenge=resp_data["challenge"])
|
|
117
|
+
{
|
|
118
|
+
"errorId":0,
|
|
119
|
+
"status":"ready",
|
|
120
|
+
"solution":{
|
|
121
|
+
"captcha_id":"e392e1d7fd421dc63325744d5a2b9c73",
|
|
122
|
+
"lot_number":"e6c3bed2854f41f880662c48afff5dcb",
|
|
123
|
+
"pass_token":"fad5eb52fc83bf7617402fcccfb211a21e0aa1d1044",
|
|
124
|
+
"gen_time":"1693924478",
|
|
125
|
+
"captcha_output":"fN36ufW6cQN4SQ-JRDQC70nSq9UcQBg=="
|
|
126
|
+
},
|
|
127
|
+
"cost":"0.00299",
|
|
128
|
+
"ip":"1.2.3.4",
|
|
129
|
+
"createTime":1692863536,
|
|
130
|
+
"endTime":1692863556,
|
|
131
|
+
"solveCount":1,
|
|
132
|
+
"taskId":75190409731
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
>>> GeeTest(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
136
|
+
... gt=resp_data["gt"],
|
|
137
|
+
... websiteURL="https://www.geetest.com/en/demo",
|
|
138
|
+
... method=GeetestEnm.GeeTestTaskProxyless.value,
|
|
139
|
+
... userAgent="Some specific user agent",
|
|
140
|
+
... proxyType="socks5",
|
|
141
|
+
... proxyAddress="0.0.0.0",
|
|
142
|
+
... proxyPort=443,
|
|
143
|
+
... ).captcha_handler(challenge=resp_data["challenge"])
|
|
144
|
+
{
|
|
145
|
+
"errorId":0,
|
|
146
|
+
"status":"ready",
|
|
147
|
+
"solution":{
|
|
148
|
+
"captcha_id":"e392e1d7fd421dc63325744d5a2b9c73",
|
|
149
|
+
"lot_number":"e6c3bed2854f41f880662c48afff5dcb",
|
|
150
|
+
"pass_token":"fad5eb52fc83bf7617402fcccfb211a21e0aa1d1044",
|
|
151
|
+
"gen_time":"1693924478",
|
|
152
|
+
"captcha_output":"fN36ufW6cQN4SQ-JRDQC70nSq9UcQBg=="
|
|
153
|
+
},
|
|
154
|
+
"cost":"0.00299",
|
|
155
|
+
"ip":"1.2.3.4",
|
|
156
|
+
"createTime":1692863536,
|
|
157
|
+
"endTime":1692863556,
|
|
158
|
+
"solveCount":1,
|
|
159
|
+
"taskId":75190409731
|
|
160
|
+
}
|
|
161
|
+
Returns:
|
|
162
|
+
Dict with full server response
|
|
163
|
+
|
|
164
|
+
Notes:
|
|
165
|
+
https://rucaptcha.com/api-docs/geetest
|
|
166
|
+
"""
|
|
167
|
+
self.method = method
|
|
168
|
+
super().__init__(method=self.method, *args, **kwargs)
|
|
169
|
+
# check user params
|
|
170
|
+
if self.method not in GeetestEnm.list_values():
|
|
171
|
+
raise ValueError(f"Invalid method parameter set, available - {GeetestEnm.list_values()}")
|
|
172
|
+
|
|
173
|
+
# insert `gt` param to payload
|
|
174
|
+
self.create_task_payload["task"].update(
|
|
175
|
+
{
|
|
176
|
+
"websiteURL": websiteURL,
|
|
177
|
+
"gt": gt,
|
|
178
|
+
"version": version,
|
|
179
|
+
"initParameters": initParameters,
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
def captcha_handler(self, challenge: str, **kwargs) -> dict:
|
|
184
|
+
"""
|
|
185
|
+
Sync solving method
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
challenge: The value of the challenge parameter found on the site
|
|
189
|
+
kwargs: Parameters for the `requests` library
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
Dict with full server response
|
|
193
|
+
|
|
194
|
+
Notes:
|
|
195
|
+
Check class docstirng for more info
|
|
196
|
+
"""
|
|
197
|
+
self.create_task_payload["task"].update({"challenge": challenge})
|
|
198
|
+
|
|
199
|
+
return self._processing_response(**kwargs)
|
|
200
|
+
|
|
201
|
+
async def aio_captcha_handler(self, challenge: str) -> dict:
|
|
202
|
+
"""
|
|
203
|
+
Async solving method
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
challenge: The value of the challenge parameter found on the site
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
Dict with full server response
|
|
210
|
+
|
|
211
|
+
Notes:
|
|
212
|
+
Check class docstirng for more info
|
|
213
|
+
"""
|
|
214
|
+
self.create_task_payload["task"].update({"challenge": challenge})
|
|
215
|
+
|
|
216
|
+
return await self._aio_processing_response()
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Union, Optional
|
|
4
|
+
|
|
5
|
+
from .core.base import BaseCaptcha
|
|
6
|
+
from .core.enums import GridCaptchaEnm, SaveFormatsEnm
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GridCaptcha(BaseCaptcha):
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
comment: str = "Check elements at Grid",
|
|
13
|
+
save_format: Union[str, SaveFormatsEnm] = SaveFormatsEnm.TEMP,
|
|
14
|
+
img_clearing: bool = True,
|
|
15
|
+
img_path: str = "PythonRuCaptchaBoundingBox",
|
|
16
|
+
*args,
|
|
17
|
+
**kwargs,
|
|
18
|
+
):
|
|
19
|
+
"""
|
|
20
|
+
The class is used to work with Bounding Box.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
rucaptcha_key: User API key
|
|
24
|
+
save_format: The format in which the image will be saved, or as a temporary file - 'temp',
|
|
25
|
+
or as a regular image to a folder created by the library - 'const'.
|
|
26
|
+
img_clearing: True - delete file after solution, False - don't delete file after solution
|
|
27
|
+
img_path: Folder to save captcha images
|
|
28
|
+
kwargs: Additional not required params for this captcha type
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
>>> GridCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
32
|
+
... ).captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
|
|
33
|
+
{
|
|
34
|
+
"errorId":0,
|
|
35
|
+
"status":"ready",
|
|
36
|
+
"solution":{
|
|
37
|
+
"click":[
|
|
38
|
+
1, 5, 9
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
"cost":0.033,
|
|
42
|
+
"ip":"46.53.241.91",
|
|
43
|
+
"createTime":1696730723,
|
|
44
|
+
"endTime":1696730723,
|
|
45
|
+
"solveCount":1,
|
|
46
|
+
"taskId":74708110322
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
>>> GridCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
50
|
+
... ).captcha_handler(captcha_file="src/examples/grid.png")
|
|
51
|
+
{
|
|
52
|
+
"errorId":0,
|
|
53
|
+
"status":"ready",
|
|
54
|
+
"solution":{
|
|
55
|
+
"click":[
|
|
56
|
+
1, 5, 9
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
"cost":0.033,
|
|
60
|
+
"ip":"46.53.241.91",
|
|
61
|
+
"createTime":1696730723,
|
|
62
|
+
"endTime":1696730723,
|
|
63
|
+
"solveCount":1,
|
|
64
|
+
"taskId":74708110322
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
>>> with open("src/examples/grid.png", "rb") as f:
|
|
68
|
+
... file_data = f.read()
|
|
69
|
+
>>> GridCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
|
|
70
|
+
... ).captcha_handler(captcha_base64=file_data)
|
|
71
|
+
{
|
|
72
|
+
"errorId":0,
|
|
73
|
+
"status":"ready",
|
|
74
|
+
"solution":{
|
|
75
|
+
"click":[
|
|
76
|
+
1, 5, 9
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
"cost":0.033,
|
|
80
|
+
"ip":"46.53.241.91",
|
|
81
|
+
"createTime":1696730723,
|
|
82
|
+
"endTime":1696730723,
|
|
83
|
+
"solveCount":1,
|
|
84
|
+
"taskId":74708110322
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
>>> await GridCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
88
|
+
... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
|
|
89
|
+
{
|
|
90
|
+
"errorId":0,
|
|
91
|
+
"status":"ready",
|
|
92
|
+
"solution":{
|
|
93
|
+
"click":[
|
|
94
|
+
1, 5, 9
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
"cost":0.033,
|
|
98
|
+
"ip":"46.53.241.91",
|
|
99
|
+
"createTime":1696730723,
|
|
100
|
+
"endTime":1696730723,
|
|
101
|
+
"solveCount":1,
|
|
102
|
+
"taskId":74708110322
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
>>> await GridCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
106
|
+
... ).aio_captcha_handler(captcha_file="src/examples/grid.png")
|
|
107
|
+
{
|
|
108
|
+
"errorId":0,
|
|
109
|
+
"status":"ready",
|
|
110
|
+
"solution":{
|
|
111
|
+
"click":[
|
|
112
|
+
1, 5, 9
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
"cost":0.033,
|
|
116
|
+
"ip":"46.53.241.91",
|
|
117
|
+
"createTime":1696730723,
|
|
118
|
+
"endTime":1696730723,
|
|
119
|
+
"solveCount":1,
|
|
120
|
+
"taskId":74708110322
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Death Captcha
|
|
124
|
+
|
|
125
|
+
>>> GridCaptcha(rucaptcha_key="some_username:some_password",
|
|
126
|
+
... service_type="deathbycaptcha"
|
|
127
|
+
... ).captcha_handler(captcha_file="src/examples/grid.jpg")
|
|
128
|
+
{
|
|
129
|
+
"errorId":0,
|
|
130
|
+
"status":"ready",
|
|
131
|
+
"solution":{
|
|
132
|
+
"click":[
|
|
133
|
+
1, 5, 9
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
"cost":0.033,
|
|
137
|
+
"ip":"46.53.241.91",
|
|
138
|
+
"createTime":1696730723,
|
|
139
|
+
"endTime":1696730723,
|
|
140
|
+
"solveCount":1,
|
|
141
|
+
"taskId":74708110322
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
>>> await GridCaptcha(rucaptcha_key="some_username:some_password",
|
|
145
|
+
... service_type="deathbycaptcha"
|
|
146
|
+
... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
|
|
147
|
+
{
|
|
148
|
+
"errorId":0,
|
|
149
|
+
"status":"ready",
|
|
150
|
+
"solution":{
|
|
151
|
+
"click":[
|
|
152
|
+
1, 5, 9
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
"cost":0.033,
|
|
156
|
+
"ip":"46.53.241.91",
|
|
157
|
+
"createTime":1696730723,
|
|
158
|
+
"endTime":1696730723,
|
|
159
|
+
"solveCount":1,
|
|
160
|
+
"taskId":74708110322
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
>>> with open("src/examples/grid.png", "rb") as f:
|
|
164
|
+
... file_data = f.read()
|
|
165
|
+
>>> await GridCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
|
|
166
|
+
... ).aio_captcha_handler(captcha_base64=file_data)
|
|
167
|
+
{
|
|
168
|
+
"errorId":0,
|
|
169
|
+
"status":"ready",
|
|
170
|
+
"solution":{
|
|
171
|
+
"click":[
|
|
172
|
+
1, 5, 9
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
"cost":0.033,
|
|
176
|
+
"ip":"46.53.241.91",
|
|
177
|
+
"createTime":1696730723,
|
|
178
|
+
"endTime":1696730723,
|
|
179
|
+
"solveCount":1,
|
|
180
|
+
"taskId":74708110322
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
Dict with full server response
|
|
185
|
+
|
|
186
|
+
Notes:
|
|
187
|
+
https://2captcha.com/api-docs/grid
|
|
188
|
+
|
|
189
|
+
https://rucaptcha.com/api-docs/grid
|
|
190
|
+
"""
|
|
191
|
+
super().__init__(method=GridCaptchaEnm.GridTask.value, *args, **kwargs)
|
|
192
|
+
|
|
193
|
+
self.save_format = save_format
|
|
194
|
+
self.img_clearing = img_clearing
|
|
195
|
+
self.img_path = img_path
|
|
196
|
+
|
|
197
|
+
self.create_task_payload["task"].update({"comment": comment})
|
|
198
|
+
|
|
199
|
+
def captcha_handler(
|
|
200
|
+
self,
|
|
201
|
+
captcha_link: Optional[str] = None,
|
|
202
|
+
captcha_file: Optional[str] = None,
|
|
203
|
+
captcha_base64: Optional[bytes] = None,
|
|
204
|
+
**kwargs,
|
|
205
|
+
) -> dict:
|
|
206
|
+
"""
|
|
207
|
+
Sync solving method
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
captcha_link: Captcha image URL
|
|
211
|
+
captcha_file: Captcha image file path
|
|
212
|
+
captcha_base64: Captcha image BASE64 info
|
|
213
|
+
kwargs: additional params for `requests` library
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
Dict with full server response
|
|
217
|
+
|
|
218
|
+
Notes:
|
|
219
|
+
Check class docstirng for more info
|
|
220
|
+
"""
|
|
221
|
+
self._body_file_processing(
|
|
222
|
+
save_format=self.save_format,
|
|
223
|
+
file_path=self.img_path,
|
|
224
|
+
captcha_link=captcha_link,
|
|
225
|
+
captcha_file=captcha_file,
|
|
226
|
+
captcha_base64=captcha_base64,
|
|
227
|
+
**kwargs,
|
|
228
|
+
)
|
|
229
|
+
logging.warning(f"{self.result = }")
|
|
230
|
+
logging.warning(f"{self.create_task_payload = }")
|
|
231
|
+
if not self.result.errorId:
|
|
232
|
+
return self._processing_response(**kwargs)
|
|
233
|
+
return self.result.to_dict()
|
|
234
|
+
|
|
235
|
+
async def aio_captcha_handler(
|
|
236
|
+
self,
|
|
237
|
+
captcha_link: Optional[str] = None,
|
|
238
|
+
captcha_file: Optional[str] = None,
|
|
239
|
+
captcha_base64: Optional[bytes] = None,
|
|
240
|
+
**kwargs,
|
|
241
|
+
) -> dict:
|
|
242
|
+
"""
|
|
243
|
+
Async solving method
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
captcha_link: Captcha image URL
|
|
247
|
+
captcha_file: Captcha image file path
|
|
248
|
+
captcha_base64: Captcha image BASE64 info
|
|
249
|
+
kwargs: additional params for `aiohttp` library
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
Dict with full server response
|
|
253
|
+
|
|
254
|
+
Notes:
|
|
255
|
+
Check class docstirng for more info
|
|
256
|
+
"""
|
|
257
|
+
await self._aio_body_file_processing(
|
|
258
|
+
save_format=self.save_format,
|
|
259
|
+
file_path=self.img_path,
|
|
260
|
+
captcha_link=captcha_link,
|
|
261
|
+
captcha_file=captcha_file,
|
|
262
|
+
captcha_base64=captcha_base64,
|
|
263
|
+
**kwargs,
|
|
264
|
+
)
|
|
265
|
+
if not self.result.errorId:
|
|
266
|
+
return await self._aio_processing_response()
|
|
267
|
+
return self.result.to_dict()
|
|
268
|
+
|
|
269
|
+
def __del__(self):
|
|
270
|
+
if self.save_format == SaveFormatsEnm.CONST.value and self.img_clearing:
|
|
271
|
+
shutil.rmtree(self.img_path)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from .core.base import BaseCaptcha
|
|
4
|
+
from .core.enums import HCaptchaEnm
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HCaptcha(BaseCaptcha):
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
websiteURL: str,
|
|
11
|
+
websiteKey: str,
|
|
12
|
+
method: Union[str, HCaptchaEnm] = HCaptchaEnm.HCaptchaTaskProxyless,
|
|
13
|
+
*args,
|
|
14
|
+
**kwargs,
|
|
15
|
+
):
|
|
16
|
+
"""
|
|
17
|
+
The class is used to work with HCaptcha.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
rucaptcha_key: User API key
|
|
21
|
+
websiteURL: Full URL of the captcha page
|
|
22
|
+
websiteKey: The value of the `data-sitekey` parameter found on the site
|
|
23
|
+
method: Captcha type
|
|
24
|
+
kwargs: Not required params for task creation request
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
>>> HCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
28
|
+
... websiteKey="3ceb8624-1970-4e6b-91d5-70317b70b651",
|
|
29
|
+
... websiteURL="https://rucaptcha.com/demo/hcaptcha",
|
|
30
|
+
... method=HCaptchaEnm.HCaptchaTaskProxyless.value
|
|
31
|
+
... ).captcha_handler()
|
|
32
|
+
{
|
|
33
|
+
"errorId":0,
|
|
34
|
+
"status":"ready",
|
|
35
|
+
"solution":{
|
|
36
|
+
"token":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A",
|
|
37
|
+
"respKey":"E0_eyJ0eXAiOiJK...y2w5_YbP8PGuJBBo",
|
|
38
|
+
"userAgent":"Mozilla/5.0 (.......",
|
|
39
|
+
"gRecaptchaResponse":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A"
|
|
40
|
+
},
|
|
41
|
+
"cost":"0.00299",
|
|
42
|
+
"ip":"1.2.3.4",
|
|
43
|
+
"createTime":1692863536,
|
|
44
|
+
"endTime":1692863556,
|
|
45
|
+
"solveCount":1,
|
|
46
|
+
"taskId": 73243152973,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
>>> await HCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
|
|
50
|
+
... websiteKey="3ceb8624-1970-4e6b-91d5-70317b70b651",
|
|
51
|
+
... websiteURL="https://rucaptcha.com/demo/hcaptcha",
|
|
52
|
+
... method=HCaptchaEnm.HCaptchaTaskProxyless.value
|
|
53
|
+
... ).aio_captcha_handler()
|
|
54
|
+
{
|
|
55
|
+
"errorId":0,
|
|
56
|
+
"status":"ready",
|
|
57
|
+
"solution":{
|
|
58
|
+
"token":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A",
|
|
59
|
+
"respKey":"E0_eyJ0eXAiOiJK...y2w5_YbP8PGuJBBo",
|
|
60
|
+
"userAgent":"Mozilla/5.0 (........",
|
|
61
|
+
"gRecaptchaResponse":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A"
|
|
62
|
+
},
|
|
63
|
+
"cost":"0.00299",
|
|
64
|
+
"ip":"1.2.3.4",
|
|
65
|
+
"createTime":1692863536,
|
|
66
|
+
"endTime":1692863556,
|
|
67
|
+
"solveCount":1,
|
|
68
|
+
"taskId": 73243152973,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Dict with full server response
|
|
73
|
+
|
|
74
|
+
Notes:
|
|
75
|
+
https://rucaptcha.com/api-docs/hcaptcha
|
|
76
|
+
"""
|
|
77
|
+
super().__init__(method=method, *args, **kwargs)
|
|
78
|
+
|
|
79
|
+
self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})
|
|
80
|
+
|
|
81
|
+
# check user params
|
|
82
|
+
if method not in HCaptchaEnm.list_values():
|
|
83
|
+
raise ValueError(f"Invalid method parameter set, available - {HCaptchaEnm.list_values()}")
|
|
84
|
+
|
|
85
|
+
def captcha_handler(self, **kwargs) -> dict:
|
|
86
|
+
"""
|
|
87
|
+
Sync solving method
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
kwargs: Parameters for the `requests` library
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
Dict with full server response
|
|
94
|
+
|
|
95
|
+
Notes:
|
|
96
|
+
Check class docstirng for more info
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
return self._processing_response(**kwargs)
|
|
100
|
+
|
|
101
|
+
async def aio_captcha_handler(self) -> dict:
|
|
102
|
+
"""
|
|
103
|
+
Async solving method
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
Dict with full server response
|
|
107
|
+
|
|
108
|
+
Notes:
|
|
109
|
+
Check class docstirng for more info
|
|
110
|
+
"""
|
|
111
|
+
return await self._aio_processing_response()
|