python获取图片验证码

Posted songge1209

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python获取图片验证码相关的知识,希望对你有一定的参考价值。

一、安装linux下图片处理工具:

# which tesseract
/usr/bin/tesseract

二、安装python连接模块:

pip install pytesseract

pip install Pillow

三、进入python运行环境:

1报错:

File "/usr/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 194, in image_to_string
return run_and_get_output(image, ‘txt‘, lang, config, nice)
File "/usr/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 141, in run_and_get_output
run_tesseract(**kwargs)
File "/usr/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 112, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

 

修改源码:

vim /usr/lib/python2.7/site-packages/pytesseract/pytesseract.py

修改为绝对路径:(

tesseract_cmd = ‘/usr/bin/tesseract‘

>>> import pytesseract
>>> from PIL import Image
>>> image = Image.open(‘/tmp/cap.jpg‘)
>>> vcode = pytesseract.image_to_string(image)

>>> print(vcode)
blZgb
















以上是关于python获取图片验证码的主要内容,如果未能解决你的问题,请参考以下文章

python+appium自动化测试获取短信+图片验证码

Mac + Python + Selenium之获取验证码图片code并进行登录

python接口自动化怎么串联登录接口与图形验证码借口

Python 实现识别弱图片验证码

爬虫验证码

Python 实现简单图片验证码登录