通过百度云获得图片验证码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time:2022/05/16 10:21
# @Author:Hero
# @File:VerCodeFromBaidu.py
# @Sofeware :PyCharm

'''
  通过百度云 获得 图片验证码
'''

import os
from aip import AipOcr
class getwords():
    def __init__(self, filePath):
        super(getwords, self).__init__()
        self.__filePath = filePath

    def get_file_content(self, filePath):
        with open(filePath, "rb") as fp:
            return fp.read()
    
    def getwords(self):
        """ 你的 APPID AK SK
            APP_ID = '你的 App ID'
            API_KEY = '你的 Api Key'
            SECRET_KEY = '你的 Secret Key'
        """
        APP_ID = '26238932'
        API_KEY = 'MdA7GCAME5AO9sTaPDU0ZuhI'
        SECRET_KEY = 'Your key of baidu'
    
        client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
        image = self.get_file_content(self.__filePath)
        # url = "https://www.x.com/sample.jpg"
        # pdf_file = get_file_content('文件路径')
    
        # 调用通用文字识别(标准版)
        res_image = client.basicGeneral(image)
        # res_url = client.basicGeneralUrl(url)
        # res_pdf = client.basicGeneralPdf(pdf_file)
    
        # print(res_image['words_result'][0]['words'])
        # return res_image['words_result'][0]['words']
        return res_image

if __name__ == '__main__':
    # t = getwords(os.path.join(os.getcwd(), "imgVeriCode.png"))
    t = getwords("e://fms2022/imgVeriCode.png")
    wd = t.getwords()
    print(wd)
    print(wd['words_result'][0]['words'])

posted @ 2023-07-11 14:23  冀未然  阅读(39)  评论(0)    收藏  举报