pyhton验证码识别

1、PIL 下载地址: PIL-1.1.7.win-amd64-py2.7.exe

2、tesseract-ocr下载地址: tesseract-ocr-setup-3.02.02.exe

3、pytesseract安装 直接使用pip install pytesseract安装即可,或者使用easy_install pytesseract

下载链接:http://pan.baidu.com/s/1hrVRHYG

#!/usr/bin/env python
# -*- coding: utf-8 -*-


'''

try:
    import pytesseract
    from PIL import Image
except ImportError:
    print '模块导入错误,请使用pip安装,pytesseract依赖以下库:'
    print 'http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil'
    print 'http://code.google.com/p/tesseract-ocr/'
    raise SystemExit
 
image = Image.open('vcode.png')
vcode = pytesseract.image_to_string(image)
print vcode
'''

import pytesseract
from PIL import Image
import requests

def Vercode():
	url = "http://www.xxxx"
	header = {"user_agent":"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"}
	r =requests.get(url,headers=header,timeout=5)
	with open('vcode.jpg','wb') as pic:
		pic.write(r.content)
	im = pytesseract.image_to_string(Image.open('vcode.jpg'))
	im = im.replace(' ', '')
	if im != '':
		return im
	else:
		return Vercode()
print Vcode()

 

参考文章:

  [python]python验证码识别 https://www.waitalone.cn/python-php-ocr.html

  网络信息安全攻防学习平台脚本关过关攻略 https://www.waitalone.cn/security-scripts-game.html

  http://hackinglab.cn/ShowQues.php?type=scripts