- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify_code.py
More file actions
Latest commit
31 lines (27 loc) · 1.03 KB
/
Copy pathverify_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
importos,itertools,re,urllib
'''分析得到验证码'''
defgetVerify_Code(fileName):
r=r'^[a-zA-Z0-9]{5}$'
cmdList=['-colorspace gray','-monochrome']
scaleList=[i*100foriinrange(1,6)]
fors,cinitertools.product(scaleList,cmdList):
cmds='convert.exe -compress none -depth 8 -alpha off -scale {0} {1} {2} code.tif '.format(s,c,fileName)
printcmds
os.system(cmds)
os.system('tesseract -l eng code.tif rr')
strx=open('rr.txt','r').read().replace(' ','').replace('_','').strip()
printstrx
m=re.search('\d+[\+\-\*\/]\d+',strx)
ifm:
strx=m.group(0)
strx=eval(strx)
returnstrx
elifre.match(r,strx):
returnstrx
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')
printu'找到了,{0}'.format(xxx) ifxxx!=''elseu'没有找到'