-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathamazon_waf.py
More file actions
158 lines (146 loc) · 6.11 KB
/
amazon_waf.py
File metadata and controls
158 lines (146 loc) · 6.11 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from typing import Union, Optional
from .core.base import CaptchaParams
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
__all__ = ("AmazonWAF",)
class AmazonWAF(CaptchaParams):
def __init__(
self,
api_key: str,
captcha_type: Union[CaptchaTypeEnm, str],
websiteURL: str,
websiteKey: str,
iv: str,
context: str,
proxyType: Optional[Union[ProxyTypeEnm, str]] = None,
proxyAddress: Optional[str] = None,
proxyPort: Optional[int] = None,
proxyLogin: Optional[str] = None,
proxyPassword: Optional[str] = None,
userAgent: Optional[str] = None,
sleep_time: Optional[int] = 10,
):
"""
The class is used to work with FunCaptcha.
Args:
api_key: Capsolver API key
captcha_type: Captcha type
websiteURL: Address of a target web page. Can be located anywhere on the web site, even in a member area
websiteKey: Value of key from window.gokuProps object in WAF page source code
iv: Value of iv from window.gokuProps object in WAF page source code
context: Value of context from window.gokuProps object in WAF page source code
proxyType: Type of the proxy
proxyAddress: Proxy IP address IPv4/IPv6. Not allowed to use:
host names instead of IPs,
transparent proxies (where client IP is visible),
proxies from local networks (192.., 10.., 127...)
proxyPort: Proxy port.
proxyLogin: Proxy login.
proxyPassword: Proxy password.
userAgent: Browser UserAgent.
sleep_time: The waiting time between requests to get the result of the Captcha
Examples:
>>> AmazonWAF(api_key="99d7d111a0111dc11184111c8bb111da",
... captcha_type="AmazonTaskProxyless",
... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
... websiteKey="AQIDAgghr5y45ywZwdADFLWk7XOA==",
... iv="CgAAXFFFFSAAABVk",
... context="qoJYgnKscdqwdqwdqwaormh/dYYK+Y=",
... ).captcha_handler()
{
"errorId": 0,
"errorCode": None,
"errorDescription": None,
"status":"ready",
"solution":{
"token":"0.Qz0.....f1"
},
"cost": 0.002,
"ip": "46.53.249.230",
"createTime": 1679004358,
"endTime": 1679004368,
"solveCount": 0,
"taskId": 396687629
}
>>> await AmazonWAF(api_key="99d7d111a0111dc11184111c8bb111da",
... captcha_type="AmazonTaskProxyless",
... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
... websiteKey="AQIDAgghr5y45ywZwdADFLWk7XOA==",
... iv="CgAAXFFFFSAAABVk",
... context="qoJYgnKscdqwdqwdqwaormh/dYYK+Y=",
... ).aio_captcha_handler()
{
"errorId": 0,
"errorCode": None,
"errorDescription": None,
"status":"ready",
"solution":{
"token":"0.Qz0.....f1"
},
"cost": 0.002,
"ip": "46.53.249.230",
"createTime": 1679004358,
"endTime": 1679004368,
"solveCount": 0,
"taskId": 396687629
}
>>> AmazonWAF(api_key="99d7d111a0111dc11184111c8bb111da",
... captcha_type="AmazonTaskProxyless",
... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
... websiteKey="AQIDAgghr5y45ywZwdADFLWk7XOA==",
... iv="CgAAXFFFFSAAABVk",
... context="qoJYgnKscdqwdqwdqwaormh/dYYK+Y=",
... proxyType="http",
... proxyAddress="0.0.0.0",
... proxyPort=9988,
... proxyLogin="proxy_login",
... proxyPassword="proxy_password",
... userAgent="some_real_user_agent",
... ).captcha_handler()
{
"errorId": 0,
"errorCode": None,
"errorDescription": None,
"status":"ready",
"solution":{
"token":"0.Qz0.....f1"
},
"cost": 0.002,
"ip": "46.53.249.230",
"createTime": 1679004358,
"endTime": 1679004368,
"solveCount": 0,
"taskId": 396687629
}
Notes:
https://anti-captcha.com/apidoc/task-types/AmazonTask
https://anti-captcha.com/apidoc/task-types/AmazonTaskProxyless
"""
super().__init__(api_key=api_key, sleep_time=sleep_time)
# validation of the received parameters
if captcha_type == CaptchaTypeEnm.AmazonTask:
self.task_params = dict(
type=captcha_type,
websiteURL=websiteURL,
websitePublicKey=websiteKey,
iv=iv,
context=context,
proxyType=proxyType,
proxyAddress=proxyAddress,
proxyPort=proxyPort,
proxyLogin=proxyLogin,
proxyPassword=proxyPassword,
userAgent=userAgent,
)
elif captcha_type == CaptchaTypeEnm.AmazonTaskProxyless:
self.task_params = dict(
type=captcha_type,
websiteURL=websiteURL,
websitePublicKey=websiteKey,
iv=iv,
context=context,
)
else:
raise ValueError(
f"Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, \
available - {CaptchaTypeEnm.FunCaptchaTaskProxyless.value,CaptchaTypeEnm.FunCaptchaTask.value}"
)