# -*- coding: utf-8 -*- # @Time : 2022/6/14 16:26 # @Author : admin # @Email : 1985264689@qq.com # @File : 自动识别.py # @Project : 项目 # @脚本说明 : import base64 import requests # client_id = "fbCrh7MQKhec8lKrqCmG8iQ1" # client_secret = "vcbEtFosTotbkGcknIugnTrFht4Mh8Gs" # # token_url = "https://aip.baidubce.com/oauth/2.0/token" # host = f"{token_url}?grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}" # # response = requests.get(host) # if response: # print(response.json()) # print(response.json()['access_token']) def get_code(): # 调用通用文字识别高精度版接口 request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic" # 参数image:图像base64编码 # 下面图片路径请自行切换为自己环境的绝对路径 resp = requests.get('http://192.168.248.184/learn/blog/vcode.php') with open('D:/vcode.png','wb') as file: file.write(resp.content) img = base64.b64encode(resp.content) params = {"image": img} access_token = '24.3a4efcd30a19bbdb145dcb24fe5e7f9e.2592000.1657789928.282335-26449397' request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, headers=headers) vcode = response.json()['words_result'][0]['words'] # 打印调用结果 print(vcode) if __name__ == '__main__': get_code()
Python 百度识别验证码
最新推荐文章于 2025-08-29 09:41:23 发布
