-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha_example.py
More file actions
93 lines (87 loc) · 3.19 KB
/
captcha_example.py
File metadata and controls
93 lines (87 loc) · 3.19 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
"""
Scrapeless Python SDK - Captcha Service Example
"""
import json
import asyncio
from scrapeless import Scrapeless
from scrapeless.types import ICreateCaptcha
# Initialize client
client = Scrapeless()
def recaptcha_example() -> None:
"""
Example for solving reCAPTCHA
"""
try:
print('Testing reCAPTCHA solving...')
req = ICreateCaptcha(
actor='captcha.recaptcha',
input={
'version': 'v2',
'pageURL': 'https://www.google.com',
'siteKey': '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-',
'pageAction': 'scraping',
'invisible': False
}
)
# The SDK may require async, but for demo, use run_until_complete
result = asyncio.get_event_loop().run_until_complete(client.captcha.captcha_solver(req))
print('✅ reCAPTCHA solving successful')
print('Result:', json.dumps(result, indent=2))
except Exception as error:
print(f'❌ reCAPTCHA solving failed: {error}')
def hcaptcha_example() -> None:
"""
Example for solving hCaptcha
"""
try:
print('Testing hCaptcha solving...')
req = ICreateCaptcha(
actor='captcha.hcaptcha',
input={
'sitekey': '10000000-ffff-ffff-ffff-000000000001',
'url': 'https://hcaptcha.com/playground'
}
)
result = asyncio.get_event_loop().run_until_complete(client.captcha.captcha_solver(req.__dict__))
print('✅ hCaptcha solving successful')
print('Result:', json.dumps(result, indent=2))
except Exception as error:
print(f'❌ hCaptcha solving failed: {error}')
def captcha_task_status_example() -> None:
"""
Example for captcha task creation and status checking
"""
try:
print('Testing captcha task creation...')
req = ICreateCaptcha(
actor='captcha.hcaptcha',
input={
'sitekey': '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
'url': 'https://recaptcha-demo.appspot.com'
}
)
task = asyncio.get_event_loop().run_until_complete(client.captcha.captcha_create(req.__dict__))
print(f"✅ Task creation successful: {task['data']['taskId']}")
print('Waiting 5 seconds before checking status...')
asyncio.get_event_loop().run_until_complete(asyncio.sleep(5))
print('Testing captcha task status check...')
status = asyncio.get_event_loop().run_until_complete(client.captcha.captcha_result_get(task['data']['taskId']))
print('✅ Task status check successful')
print('Status:', json.dumps(status['data'], indent=2))
except Exception as error:
print(f'❌ Task creation or status check failed: {error}')
def run_example() -> None:
"""
Main entry, run all captcha examples in sequence
"""
try:
recaptcha_example()
print('\n')
hcaptcha_example()
print('\n')
captcha_task_status_example()
print('\n')
print('🎉 All captcha examples completed')
except Exception as error:
print(f'❌ Error occurred during captcha examples: {error}')
run_example()