测试OCR.py 1.3 KB
Newer Older
H
hjdhnx 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : 测试OCR.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Author's Blog: https://blog.csdn.net/qq_32394351
# Date  : 2023/3/28

import requests
import base64
requests.packages.urllib3.disable_warnings()
PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'
UA = 'Mozilla/5.0'
api = 'https://api.nn.ci/ocr/b64/text'
api2 = 'http://dm.mudery.com:10000'
H
hjdhnx 已提交
15 16
# api3 = 'http://localhost:5705/parse/ocr'
api3 = 'http://cms.nokia.press:5707/parse/ocr'
H
hjdhnx 已提交
17 18 19 20
def test():
    with open('yzm1.png',mode='rb') as f:
        img = f.read()
    try:
21
        print(base64.b64encode(img).decode())
H
hjdhnx 已提交
22 23 24 25 26 27 28 29 30 31 32
        # code = requests.post(api, data=base64.b64encode(img).decode(), headers={'user-agent': PC_UA}, verify=False).text
        # code = requests.post(api, data=base64.b64encode(img).decode(), headers={'user-agent': PC_UA}, verify=False).text
        code = requests.post(api3, data={"img":base64.b64encode(img).decode()}, headers={'user-agent': PC_UA}, verify=False).text
    except Exception as e:
        print(f'ocr识别发生错误:{e}')
        code = ''
    print(f'验证码为:{code}')
    return code

if __name__ == '__main__':
    test()