0
# Cloud Provider Captchas
1
2
Methods for solving captcha systems from major cloud providers including Cloudflare Turnstile, Amazon WAF, and other enterprise-grade protection systems.
3
4
## Capabilities
5
6
### Cloudflare Turnstile
7
8
Solves Cloudflare Turnstile captcha challenges, the modern replacement for reCAPTCHA.
9
10
```python { .api }
11
def turnstile(self, sitekey, url, **kwargs):
12
"""
13
Solve Cloudflare Turnstile captcha.
14
15
Parameters:
16
- sitekey (str): Value of sitekey parameter (required)
17
- url (str): Full URL where Turnstile is located (required)
18
- useragent (str): User agent string for browser simulation
19
- action (str): Action parameter if specified on the page
20
- data (str): Custom data parameter if present
21
- pagedata (str): Additional page data parameter if present
22
- softId (int): Software developer ID
23
- callback (str): Pingback URL for result notification
24
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
25
26
Returns:
27
dict: {'captchaId': str, 'code': str} - code contains Turnstile response token
28
"""
29
```
30
31
### Amazon WAF
32
33
Solves Amazon Web Application Firewall captcha challenges.
34
35
```python { .api }
36
def amazon_waf(self, sitekey, iv, context, url, **kwargs):
37
"""
38
Solve Amazon WAF captcha.
39
40
Parameters:
41
- sitekey (str): Value of sitekey parameter (required)
42
- iv (str): Value of IV parameter (required)
43
- context (str): Value of context parameter (required)
44
- url (str): Full URL where Amazon WAF captcha is located (required)
45
- challenge_script (str): URL of challenge script if different from default
46
- captcha_script (str): URL of captcha script if different from default
47
- softId (int): Software developer ID
48
- callback (str): Pingback URL for result notification
49
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
50
51
Returns:
52
dict: {'captchaId': str, 'code': str} - code contains Amazon WAF solution
53
"""
54
```
55
56
### MTCaptcha
57
58
Solves MTCaptcha challenges, a privacy-focused captcha solution.
59
60
```python { .api }
61
def mtcaptcha(self, sitekey, url, **kwargs):
62
"""
63
Solve MTCaptcha challenges.
64
65
Parameters:
66
- sitekey (str): Value of sitekey parameter (required)
67
- url (str): Full URL where MTCaptcha is located (required)
68
- softId (int): Software developer ID
69
- callback (str): Pingback URL for result notification
70
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
71
72
Returns:
73
dict: {'captchaId': str, 'code': str} - code contains MTCaptcha response token
74
"""
75
```
76
77
### Friendly Captcha
78
79
Solves Friendly Captcha challenges, which use proof-of-work instead of user interaction.
80
81
```python { .api }
82
def friendly_captcha(self, sitekey, url, **kwargs):
83
"""
84
Solve Friendly Captcha challenges.
85
86
Parameters:
87
- sitekey (str): Value of sitekey parameter (required)
88
- url (str): Full URL where Friendly Captcha is located (required)
89
- softId (int): Software developer ID
90
- callback (str): Pingback URL for result notification
91
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
92
93
Returns:
94
dict: {'captchaId': str, 'code': str} - code contains Friendly Captcha solution
95
"""
96
```
97
98
## Usage Examples
99
100
### Cloudflare Turnstile
101
102
```python
103
from twocaptcha import TwoCaptcha
104
105
solver = TwoCaptcha('your_api_key')
106
107
# Basic Turnstile
108
result = solver.turnstile(
109
sitekey='0x1AAAAAAAAkg0s2VIWD34y',
110
url='https://example.com/turnstile-form'
111
)
112
print(f"Turnstile token: {result['code']}")
113
114
# Turnstile with custom parameters
115
result = solver.turnstile(
116
sitekey='turnstile_site_key',
117
url='https://secure-site.com/form',
118
useragent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
119
action='login',
120
data='custom_data_value'
121
)
122
print(f"Token: {result['code']}")
123
124
# Turnstile with proxy
125
result = solver.turnstile(
126
sitekey='site_key',
127
url='https://example.com',
128
proxy={'type': 'HTTPS', 'uri': 'user:pass@proxy.com:8080'}
129
)
130
print(f"Proxied token: {result['code']}")
131
```
132
133
### Amazon WAF
134
135
```python
136
from twocaptcha import TwoCaptcha
137
138
solver = TwoCaptcha('your_api_key')
139
140
# Solve Amazon WAF captcha
141
result = solver.amazon_waf(
142
sitekey='waf_site_key',
143
iv='initialization_vector',
144
context='context_string',
145
url='https://aws-protected-site.com/form'
146
)
147
print(f"Amazon WAF solution: {result['code']}")
148
149
# With custom script URLs
150
result = solver.amazon_waf(
151
sitekey='site_key',
152
iv='iv_value',
153
context='context_value',
154
url='https://example.com',
155
challenge_script='https://custom-challenge-script.js',
156
captcha_script='https://custom-captcha-script.js'
157
)
158
print(f"Solution: {result['code']}")
159
```
160
161
### MTCaptcha
162
163
```python
164
from twocaptcha import TwoCaptcha
165
166
solver = TwoCaptcha('your_api_key')
167
168
# Basic MTCaptcha
169
result = solver.mtcaptcha(
170
sitekey='mtcaptcha_site_key',
171
url='https://example.com/mt-form'
172
)
173
print(f"MTCaptcha token: {result['code']}")
174
175
# MTCaptcha with callback
176
result = solver.mtcaptcha(
177
sitekey='site_key',
178
url='https://secure-form.com',
179
callback='https://yoursite.com/captcha-callback'
180
)
181
print(f"Token: {result['code']}")
182
```
183
184
### Friendly Captcha
185
186
```python
187
from twocaptcha import TwoCaptcha
188
189
solver = TwoCaptcha('your_api_key')
190
191
# Solve Friendly Captcha (proof-of-work)
192
result = solver.friendly_captcha(
193
sitekey='friendly_site_key',
194
url='https://example.com/friendly-form'
195
)
196
print(f"Friendly Captcha solution: {result['code']}")
197
198
# With proxy for geo-restricted sites
199
result = solver.friendly_captcha(
200
sitekey='site_key',
201
url='https://geo-restricted.com',
202
proxy={'type': 'HTTPS', 'uri': 'user:pass@eu-proxy.com:8080'}
203
)
204
print(f"Solution: {result['code']}")
205
```
206
207
### Integration with Selenium
208
209
```python
210
from twocaptcha import TwoCaptcha
211
from selenium import webdriver
212
from selenium.webdriver.common.by import By
213
from selenium.webdriver.support.ui import WebDriverWait
214
from selenium.webdriver.support import expected_conditions as EC
215
216
# Setup
217
solver = TwoCaptcha('your_api_key')
218
driver = webdriver.Chrome()
219
220
try:
221
# Navigate to page with Turnstile
222
driver.get('https://example.com/turnstile-protected-form')
223
224
# Wait for Turnstile to load and get sitekey
225
turnstile_iframe = WebDriverWait(driver, 10).until(
226
EC.presence_of_element_located((By.CSS_SELECTOR, "iframe[src*='turnstile']"))
227
)
228
229
# Extract sitekey from page source
230
page_source = driver.page_source
231
# Parse sitekey from HTML (implementation depends on page structure)
232
sitekey = "extracted_sitekey_value"
233
234
# Solve Turnstile
235
result = solver.turnstile(
236
sitekey=sitekey,
237
url=driver.current_url
238
)
239
240
# Inject solution into page
241
driver.execute_script(f"""
242
document.querySelector('[name="cf-turnstile-response"]').value = '{result['code']}';
243
""")
244
245
# Submit form
246
submit_button = driver.find_element(By.CSS_SELECTOR, "input[type='submit']")
247
submit_button.click()
248
249
print(f"Form submitted with Turnstile token: {result['code']}")
250
251
finally:
252
driver.quit()
253
```
254
255
### Error Handling for Cloud Captchas
256
257
```python
258
from twocaptcha import TwoCaptcha, ApiException, ValidationException
259
260
solver = TwoCaptcha('your_api_key')
261
262
try:
263
result = solver.amazon_waf(
264
sitekey='invalid_key',
265
iv='', # Empty required parameter
266
context='context',
267
url='https://example.com'
268
)
269
except ValidationException as e:
270
print(f"Validation error: {e}")
271
except ApiException as e:
272
print(f"API error: {e}")
273
274
# Handle specific cloud captcha errors
275
try:
276
result = solver.turnstile(
277
sitekey='expired_sitekey',
278
url='https://example.com'
279
)
280
except ApiException as e:
281
if 'INVALID_SITEKEY' in str(e):
282
print("Sitekey is invalid or expired")
283
elif 'TIMEOUT' in str(e):
284
print("Captcha solving timed out")
285
else:
286
print(f"Other API error: {e}")
287
```
288
289
### Performance Optimization
290
291
```python
292
from twocaptcha import TwoCaptcha
293
import asyncio
294
import concurrent.futures
295
296
solver = TwoCaptcha('your_api_key')
297
298
def solve_turnstile(sitekey, url):
299
"""Solve single Turnstile captcha"""
300
return solver.turnstile(sitekey=sitekey, url=url)
301
302
# Solve multiple captchas concurrently
303
sitekeys_and_urls = [
304
('sitekey1', 'https://site1.com'),
305
('sitekey2', 'https://site2.com'),
306
('sitekey3', 'https://site3.com')
307
]
308
309
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
310
futures = [
311
executor.submit(solve_turnstile, sitekey, url)
312
for sitekey, url in sitekeys_and_urls
313
]
314
315
results = []
316
for future in concurrent.futures.as_completed(futures):
317
try:
318
result = future.result()
319
results.append(result['code'])
320
print(f"Solved: {result['code']}")
321
except Exception as e:
322
print(f"Error: {e}")
323
324
print(f"Total solved: {len(results)}")
325
```