因为需要使用OCR库作为爬虫验证码识别的工具,所以本地进行tesserocr的安装,期间各种报错,折腾了一两个小时,本次记录下所有的趟坑经历。
关于OCR:
即 Optical Character Recognition,光学字符识别,是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程。对于图形验证码来说,它们都是一些不规则的字符,这些字符确实是由字符稍加扭曲变换得到的内容。我们可以使用 OCR 技术来将其转化为电子文本,然后爬虫将识别结果提交给服务器,便可以达到自动识别验证码的过程。
相关链接
- tesserocr GitHub:https://github.com/sirfz/tesserocr
- tesserocr PyPI:https://pypi.python.org/pypi/tesserocr
- tesseract 下载地址:http://digi.bib.uni-mannheim.de/tesseract
- tesseract GitHub:https://github.com/tesseract-ocr/tesseract
- tesseract 语言包:https://github.com/tesseract-ocr/tessdata
- tesseract 文档:https://github.com/tesseract-ocr/tesseract/wiki/Documentation
(1)tesseract安装
tesserocr 是 Python 的一个 OCR 识别库,但其实是对 tesseract 做的一层 Python API 封装,所以它的核心是 tesseract。因此,在安装 tesserocr 之前,我们需要先安装 tesseract。
访问http://digi.bib.uni-mannheim.de/tesseract下载相应exe安装包,选择指定路径,傻瓜式安装即可。
(2)tesserocr安装
执行命令:pip3 install tesserocr pillow
------------------------------------------ 麻烦开始了------------------------------------
报错1:提示“Microsoft Visual C++ 14.0 is required”
网上解决办法:通过visual c++ build tools下载安装,
傻傻的我:跟着做了,想着能避免以后再遇到这个报错。安装过程比较耗时,还巨费磁盘空间,差评的操作。
网上找的一个连接:
链接: https://pan.baidu.com/s/1uenX2TJXuH2ELtLy1vOawA
提取码: 7pp8
上面操作完了,本以为OK了,继续运行,然后有出现如下错误
报错2: 提示“ error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2”
去你的吧,换个思路吧。。。。。
【终极解决方案】
换用whl安装吧
whl安装包下载链接:https://github.com/simonflueckiger/tesserocr-windows_build/releases
运行命令: pip3 install tesserocr-2.4.0-cp37-cp37m-win_amd64.whl
成功安装,真香