python识别验证码

1、python识别验证码依赖 tesseract-ocr-setup-3.02.02.exe,所以首先需要安装 tesseract-ocr-setup-3.02.02.exe

2、然后安装pytesseract,通过pytesseract调用tesseract-ocr来识别验证码。pip install pytesseract

运行代码:

import requests
from PIL import Image
from StringIO import StringIO
import pytesseract

res = requests.get('http://xxxxx/validateCode?')
#print res.content
i = Image.open(StringIO(res.content))
i.save('code.jpg','JPEG')
print pytesseract.image_to_string(i)
posted @ 2017-11-04 08:58  cppsurain  阅读(236)  评论(0编辑  收藏  举报