crac

导航

使用百度ocr接口识别验证码

#!/usr/bin/env python
#created by Baird

from aip import AipOcr

def GetCaptchaV(filename):
    APP_ID = '1X4X8X4X'
    API_KEY = 'YaVcqamctoYqRHNGAqwVbn97UO'
    SECRET_KEY = 'C1926rIqGstqPHTUFa6sz481fjDua2pv'

    client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

    """ 读取图片 """
    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()

    image = get_file_content(filename)

    """ 调用通用文字识别, 图片参数为本地图片 """
    ret = client.basicGeneral(image)

    code = ret["words_result"][0]["words"]
    print("识别验证码成功===》",code)
    return code

  

posted on 2018-09-25 14:19  crac  阅读(3671)  评论(0编辑  收藏  举报