Skip to content
This repository was archived by the owner on Mar 5, 2021. It is now read-only.

Commit 3643dc4

Browse files
added recaptcha v3 support
1 parent 258c433 commit 3643dc4

File tree

3 files changed

+52
-30
lines changed

3 files changed

+52
-30
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,23 @@ ita.solve_captcha('http://abc.com/your_captcha.jpg')
5959
For recaptcha submission there are two things that are required.
6060
- page_url
6161
- site_key
62+
- type - can be one of this 3 values: `1` - normal, `2` - invisible, `3` - v3 (it's optional, defaults to `1`)
63+
- v3_min_score - minimum score to target for v3 recaptcha `- optional`
64+
- v3_action - action parameter to use for v3 recaptcha `- optional`
65+
- proxy - proxy to use when solving recaptcha, eg. `12.34.56.78:1234` or `12.34.56.78:1234:user:password` `- optional`
66+
- user_agent - useragent to use when solve recaptcha `- optional`
67+
6268
``` python
63-
captcha_id = ita.submit_recaptcha(page_url, sitekey) # submit captcha first, to get ID
69+
recaptcha_params = {
70+
'page_url' : 'example.com',
71+
'sitekey' : '6FDDs34g3321-3234fgfh23rv32fgtrrsv3c',
72+
'type' : 3, # optional, 1 - normal recaptcha, 2 - invisible recaptcha, 3 - v3 recaptcha, default: 1
73+
'v3_min_score' : .3, # optional
74+
'v3_action' : 'homepage', # optional
75+
'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password
76+
'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' # optional
77+
}
78+
captcha_id = ita.submit_recaptcha(recaptcha_params)
6479
```
6580
This method returns a captchaID. This ID will be used next, to retrieve the g-response, once workers have
6681
completed the captcha. This takes somewhere between 10-80 seconds.
@@ -98,19 +113,6 @@ As a 3rd parameter in the constructor, you can specify a timeout for the request
98113
ita = ImageTyperzAPI(access_token, 123, 60) # sets timeout to 60 seconds
99114
```
100115

101-
**Submit recaptcha with proxy**
102-
103-
When a proxy is submitted with the recaptcha details, the workers will complete the captcha using
104-
the provided proxy/IP.
105-
106-
``` python
107-
captcha_id = ita.submit_recaptcha(page_url, sitekey, '12.34.56.78:1234') # ip:port
108-
```
109-
Proxy with authentication is also supported
110-
``` python
111-
captcha_id = ita.submit_recaptcha(page_url, sitekey, '12.34.56.78:1234:user:password')
112-
```
113-
114116
**Get details of proxy for recaptcha**
115117

116118
In case you submitted the recaptcha with proxy, you can check the status of the proxy, if it was used or not,

imagetyperzapi2/imagetyperzapi.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
# endpoints
1313
# -------------------------------------------------------------------------------------------
1414
CAPTCHA_ENDPOINT = 'http://captchatypers.com/Forms/UploadFileAndGetTextNEW.ashx'
15-
RECAPTCHA_SUBMIT_ENDPOINT = 'http://captchatypers.com/captchaapi/UploadRecaptchaV1.ashx'
15+
RECAPTCHA_SUBMIT_ENDPOINT = 'http://captchatypers.com/captchaAPI/uploadrecaptchav1.ashx'
1616
RECAPTCHA_RETRIEVE_ENDPOINT = 'http://captchatypers.com/captchaapi/GetRecaptchaText.ashx'
1717
BALANCE_ENDPOINT = 'http://captchatypers.com/Forms/RequestBalance.ashx'
1818
BAD_IMAGE_ENDPOINT = 'http://captchatypers.com/Forms/SetBadImage.ashx'
1919
PROXY_CHECK_ENDPOINT = 'http://captchatypers.com/captchaAPI/GetReCaptchaTextJSON.ashx'
2020

2121
CAPTCHA_ENDPOINT_CONTENT_TOKEN = 'http://captchatypers.com/Forms/UploadFileAndGetTextNEWToken.ashx'
2222
CAPTCHA_ENDPOINT_URL_TOKEN = 'http://captchatypers.com/Forms/FileUploadAndGetTextCaptchaURLToken.ashx'
23-
RECAPTCHA_SUBMIT_ENDPOINT_TOKEN = 'http://captchatypers.com/captchaapi/UploadRecaptchaToken.ashx'
23+
RECAPTCHA_SUBMIT_ENDPOINT_TOKEN = 'http://captchatypers.com/captchaAPI/uploadrecaptchatoken.ashx'
2424
RECAPTCHA_RETRIEVE_ENDPOINT_TOKEN = 'http://captchatypers.com/captchaapi/GetRecaptchaTextToken.ashx'
2525
BALANCE_ENDPOINT_TOKEN = 'http://captchatypers.com/Forms/RequestBalanceToken.ashx'
2626
BAD_IMAGE_ENDPOINT_TOKEN = 'http://captchatypers.com/Forms/SetBadImageToken.ashx'
@@ -161,7 +161,14 @@ def solve_captcha(self, image_path, case_sensitive = False):
161161
# -------------------
162162
# ----------------------------------
163163
# ------------------------------
164-
def submit_recaptcha(self, page_url, sitekey, proxy = None):
164+
def submit_recaptcha(self, d):
165+
page_url = d['page_url']
166+
sitekey = d['sitekey']
167+
168+
# check for proxy
169+
proxy = None
170+
if d.has_key('proxy'): proxy = d['proxy'] # if proxy, add it
171+
165172
# check if page_url and sitekey are != None
166173
if not page_url: raise Exception('provide a valid page_url')
167174
if not sitekey: raise Exception('provide a valid sitekey')
@@ -189,6 +196,15 @@ def submit_recaptcha(self, page_url, sitekey, proxy = None):
189196
if self._affiliate_id:
190197
data['affiliateid'] = self._affiliate_id
191198

199+
# user agent
200+
if d.has_key('user_agent'): data['useragent'] = d['user_agent']
201+
202+
# v3
203+
data['recaptchatype'] = 0
204+
if d.has_key('type'): data['recaptchatype'] = d['type']
205+
if d.has_key('v3_action'): data['captchaaction'] = d['v3_action']
206+
if d.has_key('v3_min_score'): data['score'] = d['v3_min_score']
207+
192208
# make request with all data
193209
response = self._session.post(url, data=data,
194210
headers=self._headers, timeout=self._timeout)

main.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# solve captcha
88
def test_api():
9-
access_token = 'access_token_here'
109
# get access token from: http://www.imagetyperz.com/Forms/ClientHome.aspx
10+
access_token = 'access_token_here'
1111
ita = ImageTyperzAPI(access_token) # init imagetyperz api obj
1212

1313
# legacy way, will get deprecated at some point
@@ -17,20 +17,27 @@ def test_api():
1717
# ---------------------------
1818
balance = ita.account_balance() # get account balance
1919
print 'Balance: {}'.format(balance) # print balance
20-
21-
# solve image captcha
22-
# --------------------
23-
# works with URL as well, if authenticated with token
20+
#
21+
# # solve image captcha
22+
# # --------------------
23+
# # works with URL as well, if authenticated with token
2424
print 'Solving captcha ...'
2525
captcha_text = ita.solve_captcha('captcha.jpg')
2626
print 'Captcha text: {}'.format(captcha_text)
2727

2828
# solve recaptcha
29-
# check: http://www.imagetyperz.com/Forms/recaptchaapi.aspx on how to get page_url and googlekey
29+
# check https://github.com/imagetyperz-api/API-docs#submit-recaptcha for more details
3030
# -----------------------------------------------------------------------------------------------
31-
page_url = 'http://your_site_here.com'
32-
sitekey = 'your_sitekey_here'
33-
captcha_id = ita.submit_recaptcha(page_url, sitekey) # submit captcha first, to get ID
31+
recaptcha_params = {
32+
'page_url' : 'page_url_here',
33+
'sitekey' : 'sitekey_here',
34+
'type' : 1, # optional, 1 - normal recaptcha, 2 - invisible recaptcha, 3 - v3 recaptcha, default: 1
35+
#'v3_min_score' : .1, # optional
36+
#'v3_action' : 'homepage', # optional
37+
#'proxy': '126.45.34.53:345', # or 126.45.34.53:123:joe:password
38+
#'user_agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' # optional
39+
}
40+
captcha_id = ita.submit_recaptcha(recaptcha_params) # submit captcha first, to get ID
3441

3542
# check if it's still in progress (waiting to be solved), every 10 seconds
3643
print 'Waiting for recaptcha to be solved ...'
@@ -45,10 +52,7 @@ def test_api():
4552
# ita = ImageTypersAPI(access_token, 123) # init imagetyperz api obj with access_token and affiliate id
4653
# ita = ImageTypersAPI(access_token, 123, 60) # init imagetyperz api obj with access_token, affid and timeout
4754
# ita.set_user_password('your_username', 'your_password') # in case you want to use user & pass instead of token (not recommended)
48-
49-
# submit recaptcha with proxy (checks API docs for more info)
50-
# captcha_id = ita.submit_recaptcha(page_url, sitekey, '127.0.0.1:1234')
51-
# captcha_id = ita.submit_recaptcha(page_url, sitekey, '127.0.0.1:1234:user:password') # proxy auth
55+
5256
# print ita.was_proxy_used(captcha_id) # tells if proxy submitted (if any) was used or not, and if not used, reason
5357

5458
# print (ita.captcha_id) # get last captcha solved id

0 commit comments

Comments
 (0)