-
Notifications
You must be signed in to change notification settings - Fork 2
/
captcha.py
27 lines (26 loc) · 1.05 KB
/
captcha.py
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
"""
Captcha resolver related code
"""
from json import loads
from seleniumwire import webdriver
def resolve(captcha_url: str) -> str:
"""
Open a browser window the user and navigate to the URL provided.
Return cookie provided on captcha successfully
:param captcha_url: url to navigate to
:return:
"""
print("A window will be opened with a captcha. Resolve it and come back in the script")
web_browser = webdriver.Firefox()
web_browser.get(captcha_url) # Navigate to this url
print("Press enter if you resolved successfully the captcha. Instead, please exit the script")
input()
datadome = None
for request_sent in web_browser.requests:
if request_sent.url.startswith('https://geo.captcha-delivery.com/captcha/check'):
json_datadome = request_sent.response.body
datadome = loads(json_datadome)
print(datadome['cookie'].split(';')[0])
if datadome is not None:
return datadome['cookie'].split(';')[0]
raise ValueError('Captcha has not been successfully resolved')