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 requestsfrom PIL import Imagefrom StringIO import StringIOimport pytesseract res = requests.get(‘http://xxxxx/validateCode?‘)#print res.contenti = Image.open(StringIO(res.content))i.save(‘code.jpg‘,‘JPEG‘)print pytesseract.image_to_string(i)
时间: 2024-10-13 16:11:37