爬虫的时候,有时候会遇到一些验证码,常见的有滑块验证码和文字验证码,本文所讲内容将为解决文字验证码做一些准备!
pip install easyocr
以这张图片为例:
运行代码:
import easyocr
reader = easyocr.Reader(['ch_sim', 'en'])
print(reader.readtext('D:/1.png', detail=0))
运行结果如下:
这样的结果是把文字识别出来后,以列表的形式展示出来。我们可以做进一步的处理,把这些形成一个段落展示出来,具体如下:
import easyocr
reader = easyocr.Reader(['ch_sim', 'en'])
result = reader.readtext('D:/1.png', detail=0)
article = '' # 定义一个空的字符串
for i in range(len(result)):
article += result[i] # 将列表中的字符串依次拼接在一起
print(article)
运行结果如下:
妖族中至高无上的存在被称之为大圣 !宗门世家。妖魔异族。万年前上古大劫绝地天通修行界秩序崩塌。有人族小国供奉妖魔, 充当伪神。有修行宗门驱使妖魔作乱。只为香火供奉。黑山老妖踏阴风。九尾妖狐敢压龙。北明妖壬颂梵音。妖圣覆海换阴阳。李玄宗手持能升级功法的玄法戒两度穿趑,从纵横江湖的一代邪壬到依附妖魔苦苦求生的底层修士。乱世之中。李玄宗为求超脱踏入巅峰。以人身成为那搅动天下风云的混天大圣 !
安装完库,进行代码的运行,可能出现的问题:
OSError: [WinError 126] 找不到指定的模块。 Error loading “D:\Python\lib\site-packages\torch\lib\asmjit.dll” or one of its dependencies.
根据提示网址,下载相应的模块。
网络连接超时或者连接断开
可以直接下载字体模型,放到指定的路径中。
1、文字检测模型(CRAFT)
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/craft_mlt_25k.zip
2、中文(简体)模型
https://pythondict.com/go/url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/chinese_sim.zip
3、中国(传统)模型
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/chinese.zip
4、拉丁模型
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/latin.zip
5、日文模型
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/japanese.zip
6、韩文模型
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/korean.zip
7、泰文模型
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/thai.zip
8、阿拉伯文模型
https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/arabic.zip
模型这么多,平时用最多的可能就是英文和中文简体字了。
Windows:C:\Users\用户名\.EasyOCR\model
其实也可以偷懒,直接搜.EasyOCR
,然后点击model
,把字体模型放在这里。然后就解决问题了!
文章到这里就结束了,感谢您的支持!
作者:远方的星
腾讯云:https://cloud.tencent.com/developer/column/91164
CSDN:https://blog.csdn.net/qq_44921056
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。