-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwocaptcha.py
37 lines (30 loc) · 1.06 KB
/
twocaptcha.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
28
29
30
31
32
33
34
35
36
37
import requests, time
class TwoCaptcha:
def __init__(self, apikey, sitekey, url):
self.s = requests.Session()
self.apikey = apikey
self.sitekey = sitekey
self.url = url
def solve(self):
postpayload = {
'key' : self.apikey,
'method' : 'userrecaptcha',
'googlekey' : self.sitekey,
'pageurl' : self.url,
'json' : '1'
}
res = self.s.post('http://2captcha.com/in.php', data = postpayload)
capid = res.json()['request']
if capid == 'ERROR_ZERO_BALANCE':
return('ERROR_ZERO_BALANCE')
while True:
getpayload = {
'action' : 'get',
'key' : self.apikey,
'id' : capid
}
res = self.s.post('http://2captcha.com/res.php', data = getpayload)
while 'NOT_READY' in res.text:
time.sleep(5)
res = self.s.post('http://2captcha.com/res.php', data = getpayload)
return(res.text[res.text.find('|')+1:])