-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathsync_recaptcha_request.py
More file actions
38 lines (25 loc) · 1002 Bytes
/
sync_recaptcha_request.py
File metadata and controls
38 lines (25 loc) · 1002 Bytes
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
import re
from os import environ
import requests
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
api_key = environ["ANTICAPTCHA_API_KEY"]
site_key_pattern = 'data-sitekey="(.+?)"'
url = "https://www.google.com/recaptcha/api2/demo?invisible=false"
EXPECTED_RESULT = "Verification Success... Hooray!"
client = AnticaptchaClient(api_key)
session = requests.Session()
def get_form_html():
return session.get(url).text
def get_token(form_html):
site_key = re.search(site_key_pattern, form_html).group(1)
task = NoCaptchaTaskProxylessTask(website_url=url, website_key=site_key)
job = client.createTaskSmee(task, timeout=10 * 60)
return job.get_solution_response()
def form_submit(token):
return requests.post(url, data={"g-recaptcha-response": token}).text
def process():
html = get_form_html()
token = get_token(html)
return form_submit(token)
if __name__ == "__main__":
assert "Verification Success... Hooray!" in process()