-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseleniumbase_capsolver.py
More file actions
40 lines (31 loc) · 1.07 KB
/
Copy pathseleniumbase_capsolver.py
File metadata and controls
40 lines (31 loc) · 1.07 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
import os
import time
from seleniumbase import SB
def wait_for_captcha_solution(sb, timeout=60):
start_time = time.time()
while time.time() - start_time < timeout:
try:
response = sb.get_attribute("#g-recaptcha-response", "value")
if response and len(response) > 0:
return response
except Exception:
pass
sb.sleep(1)
raise TimeoutError("Timed out waiting for CAPTCHA to be solved by CapSolver.")
def main():
extension_path = os.path.abspath('capsolver_extension')
with SB(
uc=True,
extension_dir=extension_path
) as sb:
sb.open("https://www.google.com/recaptcha/api2/demo")
print('\nWaiting for CAPTCHA!')
print('--------------------')
token = wait_for_captcha_solution(sb)
print(token)
sb.wait_for_element('#recaptcha-demo-submit', timeout=60)
sb.click('#recaptcha-demo-submit')
sb.sleep(3)
sb.save_screenshot('seleniumbase_capsolver_google_recaptcha.png')
if __name__ == "__main__":
main()