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獲取圖片驗證碼