Python 接口测试 验证码识别

Python 接口测试 验证码识别

一、安装ddddocr
命令:pip install ddddocr
二、测试代码

import ddddocr
import requests
import base64

if __name__ == '__main__':
    headers = {"content-type": "application/json"}
    captcha_r = requests.get( url="输入验证码url", headers=headers )
    # 获取图片数据
    verifyCode = captcha_r.json()["result"]["verifyCode"]

    # 将图片保存到本地
    with open("D:/image.png","wb") as fh:
        fh.write(base64.decodebytes(verifyCode.encode()))
    
    # 验证码识别
    ocr = ddddocr.DdddOcr()
    with open('D:/image.png', 'rb') as f:
        img_bytes = f.read()
    res = ocr.classification(img_bytes)
    print(res)

三、结果验证
在这里插入图片描述保存到本地的图片

Python 接口测试 验证码识别_第1张图片验证结果

你可能感兴趣的:(python)