Python自动化测试验证码识别技术

 安装模块

pip install ddddocr

这样下载可能会报错,在使用pip install ddddocr之前先使用下面命令(将pip下载设置为国内镜像下载)

pip config set https://pypi.tuna.tsinghua.edu.cn/simple pyspider

国内镜像

  1. 清华:https://pypi.tuna.tsinghua.edu.cn/simple
  2. 阿里云:http://mirrors.aliyun.com/pypi/simple/
  3. 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
  4. 华中理工大学:http://pypi.hustunique.com/
  5. 山东理工大学:http://pypi.sdutlinux.org/
  6. 豆瓣:http://pypi.douban.com/simple/

简单例子

import ddddocr
ocr = ddddocr.DdddOcr()
with open('图片路径', 'rb') as f:
    img = f.read()
result  = ocr.classification(img)
print(result)

登录操作时配合指定元素截图来做:

import ddddocr
ele = driver.find_element('','') # 定位验证码图片
ele.screenshot('截图保存路径/图片名.png') # 截取验证码保存
ocr = ddddocr.DdddOcr()
with open('截图保存路径/图片名.png', 'rb') as f:
    img = f.read()
result  = ocr.classification(img)
print(result)

下载后运行可能会出现多余内容

到python\Lib\site-packages\ddddocr\__init__.py中修改如下图:

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈小瑜i

请多多支持,谢谢

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值