-
Notifications
You must be signed in to change notification settings - Fork 2
/
ocr.py
53 lines (45 loc) · 1.19 KB
/
ocr.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
51
52
53
#-*- coding=utf-8 -*-
import requests
from PIL import Image
from StringIO import StringIO
upload_url = 'http://api.yundama.com/api.php?method=upload'
query_url = 'http://api.yundama.com/api.php?method=result&cid='
#云打码的用户名、密码
username = ''
password = ''
def upload(img):
data = {
'username': username,
'password': password,
'codetype': '1005',
'appid': '1',
'appkey': '22cc5376925e9387a23cf797cb9ba745',
'timeout': '60',
'method': 'upload'
}
file_ = {'file': img}
r = requests.post(upload_url, data=data, files=file_)
retdata = r.json()
if retdata["ret"] == 0:
print '上传成功'
return retdata['cid']
else:
print '上传失败'
return False
def query_cid(cid):
url = query_url + str(cid)
while 1:
r = requests.get(url)
retdata = r.json()
if retdata["ret"] == 0:
code = retdata["text"]
print u'识别验证码:{}'.format(code)
return code
break
def captch(img):
cid = upload(img)
if cid <> False:
code = query_cid(cid)
return code
else:
return 'abcd'