-
Notifications
You must be signed in to change notification settings - Fork 192
/
captcha.py
executable file
·47 lines (41 loc) · 1.44 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
# encoding: utf-8
import json
import time
import requests
class Captcha(object):
"""docstring for Captcha"""
def __init__(self):
super(Captcha, self).__init__()
self.url = 'http://api.ysdm.net/create.json'
self.username = 'a61323636'
self.password = '123456'
self.timeout = 90
self.softid = 1
self.softkey = 'b40ffbee5c1cf4e38028c197eb2fc751'
self.typeid = 3000
def verification(self, filename):
(cnt,retry) = (0, 3)
while True:
try:
if cnt >= retry:
break # over max_retry_cnt
payload = {
'username': self.username,
'password': self.password,
'timeout': self.timeout,
'softid': self.softid,
'softkey': self.softkey,
'typeid': self.typeid,
}
multiple_files = [('image', ('captcha.gif', open(filename, 'rb'), 'image/gif')),]
r = requests.post(self.url, data=payload, files=multiple_files)
return json.loads(r.text)
except Exception, e:
cnt += 1
print('{0} [INFO] {1}'.format(
time.strftime('%Y-%m-%d %H:%M:%S'), str(e)))
else:
cnt = 0
# captcha = Captcha()
# imgurl = 'http://ce.wooyun.org/captcha.php'
# print captcha.verification(imgurl)