-
Notifications
You must be signed in to change notification settings - Fork 7
/
captcha.py
executable file
·50 lines (42 loc) · 1.33 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import urllib2, os
from StringIO import StringIO
import subprocess
def curl(*args):
curl_path = '/usr/bin/curl'
curl_list = [curl_path]
for arg in args:
# loop just in case we want to filter args in future.
curl_list.append(arg)
curl_result = subprocess.Popen(
curl_list,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE).communicate()[0]
return curl_result
def solve(captcha_url):
captcha_path = download_captcha(captcha_url);
solved_captcha = call_solver(captcha_path)
os.remove(captcha_path)
return solved_captcha
def call_solver(captcha_img_path):
creds = open("decaptcha_creds","r").read().rstrip('\n').split(':')
resp = curl('-F', 'function=picture2',
'-F', 'username=' + creds[0],
'-F', 'password=' + creds[1],
'-F', 'pict=@'+captcha_img_path,
'-F', 'pict_to=0',
'-F', 'pict_type=0',
'http://poster.de-captcher.com')
return resp.split('|')[5]
def download_captcha(url):
tempfn = os.path.basename(url)
captcha = urllib2.urlopen(url)
f = file(tempfn, "wb")
f.write(captcha.read())
f.close()
return tempfn
def main():
solved = solve("http://www.reddit.com/captcha/Y1GE8H32Q5SOTi9QWGlfHwevrfNSZMyd.png")
print "the solved captcha is: " + solved
if __name__ == '__main__':
main()