rpa使用muggle_ocr自动识别验证码

1.安装包

pip3 install rpa=1.48.1
pip3 install muggle-ocr=1.0.3

如果muggle-ocr使用pip3安装不了,只能手动安装。

百度网盘:https://pan.baidu.com/s/1K3Tq9Vz-u3oQ8tWUXBweTg

提取码:zfxi

2.代码片段

import rpa as r
import muggle_ocr

def main():
    r.init(visual_automation=True,chrome_browser=True)
    r.url('http://www.12333.gov.cn/cas/siLogin?client=goviam&service=http%3A%2F%2Fsi.12333.gov.cn%2F160469.jhtml&flag=false')

    # #输入账号密码
    r.type('//*[@id="userName"]','123456')
    r.type('//*[@id="pwd"]','123456')
   
    r.snap('//*[@id="img_captcha"]','./yzm.png')
    with open(r"./yzm.png", "rb") as f:
        b = f.read()
    # ModelType.Captcha 可识别4-6位验证码
    sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha)
    text = sdk.predict(image_bytes=b)
    r.type('//*[@id="yz_text"]',text)

if __name__ == '__main__':
    main()
import time

# 导入包
import muggle_ocr

# 初始化 model_type 包含了 ModelType.OCR/ModelType.Captcha 两种
sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.OCR)

# ModelType.Captcha 可识别光学印刷文本
with open(r"C:\\Users\\Terry\\Pictures\\close.jpg", "rb") as f:
    b = f.read()

st = time.time()
text = sdk.predict(image_bytes=b)
print(text, time.time() - st)

# ModelType.Captcha 可识别4-6位验证码
sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha)

with open(r"./yzm.png", "rb") as f:
    b = f.read()

st = time.time()
text = sdk.predict(image_bytes=b)
print(text, time.time() - st)

 

posted @ 2023-01-30 17:20  缘故为何  阅读(589)  评论(0编辑  收藏  举报