Colin is daily life record

导航

智能api识图

百度智能云

详见:https://v3u.cn/a_id_134

import requests
import base64
import urllib

# 获取token
res = requests.get('https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=7trlpUrrR4NBOLyzY5N0k4Z0&client_secret=97rQtV7gi2ySoLxLbvxME3bHvv2MdrNd')
token = res.json()['access_token']
# 开始智能识图

# 接口地址
url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token='+token
# 定义头部信息
myheaders = {'Content-Type':'application/x-www-form-urlencoded'}
# 操作图片
myimg = open('./code.png','rb')
# 读取图片
temp_img = myimg.read()
myimg.close()
# 进行base64编码
temp_data = {'image':base64.b64encode(temp_img)}
# 对图片地址进行urlencode操作
temp_data = urllib.parse.urlencode(temp_data)
# 请求视图接口
res = requests.post(url=url,data=temp_data,headers=myheaders)
# print(res.json())
code = res.json()['words_result'][0]['words']
print(code)
code = str(code).replace(' ','')
print(code)

注:百度智能云不够准确,京东

自动填写验证码

selenium: http://npm.taobao.org/mirrors/chromedriver/

posted on 2024-07-14 13:32  酷酷的瑞瑞  阅读(8)  评论(0编辑  收藏  举报