-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify_code.py
More file actions
31 lines (27 loc) · 1.03 KB
/
verify_code.py
File metadata and controls
31 lines (27 loc) · 1.03 KB
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
#coding:utf-8
import os,itertools,re,urllib
'''分析得到验证码'''
def getVerify_Code(fileName):
r=r'^[a-zA-Z0-9]{5}$'
cmdList=['-colorspace gray','-monochrome']
scaleList=[i*100 for i in range(1,6)]
for s,c in itertools.product(scaleList,cmdList):
cmds='convert.exe -compress none -depth 8 -alpha off -scale {0} {1} {2} code.tif '.format(s,c,fileName)
print cmds
os.system(cmds)
os.system('tesseract -l eng code.tif rr')
strx=open('rr.txt','r').read().replace(' ','').replace('_','').strip()
print strx
m = re.search('\d+[\+\-\*\/]\d+',strx)
if m:
strx=m.group(0)
strx=eval(strx)
return strx
elif re.match(r,strx):
return strx
return ''
if __name__=='__main__':
#uri='http://support.58.com/firewall/code/3739103579/a3aa8eed.do?rnd=0.7356960084289312'
#urllib.urlretrieve(uri,'code.jpg')
xxx=getVerify_Code('code.jpg')
print u'找到了,{0}'.format(xxx) if xxx!='' else u'没有找到'