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