1 Star 0 Fork 0

Zsheng/baidudownload

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nal.py 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
tianzhongsheng 提交于 2020-03-09 12:51 . ‘1’
# python3
import urllib.request
import urllib.parse
import urllib.error
import json
import time
import base64
import re
with open('3.jpeg', 'rb') as f: # 以二进制读取本地图片
data = f.read()
encodestr = str(base64.b64encode(data), 'utf-8')
# 请求头
headers = {
'Authorization': 'APPCODE 712d406485a44077a7e72d7b03a2af36',
'Content-Type': 'application/json; charset=UTF-8'
}
def getImg(url):
with open(url, 'rb') as f: # 以二进制读取本地图片
data = f.read()
return str(base64.b64encode(data), 'utf-8')
def posturl(url, data={}):
try:
params = json.dumps(dict).encode(encoding='UTF8')
req = urllib.request.Request(url, params, headers)
r = urllib.request.urlopen(req)
html = r.read()
r.close();
return html.decode("utf8")
except urllib.error.HTTPError as e:
print(e.code)
print(e.read().decode("utf8"))
time.sleep(1)
def getYzm(dict):
try:
url = "https://ocrapi-advanced.taobao.com/ocrservice/advanced"
params = json.dumps(dict).encode(encoding='UTF8')
req = urllib.request.Request(url, params, headers)
r = urllib.request.urlopen(req)
html = r.read()
r.close();
ss = html.decode("utf8")
print(ss)
ss1 = json.loads(ss)
aa = ss1['content']
# aa = ss1['prism_wordsInfo'][0]['word']
kk = re.sub('\s', '', aa)
return kk
except urllib.error.HTTPError as e:
print(e.code)
print(e.read().decode("utf8"))
time.sleep(1)
ss = getImg('23.jpeg')
dict = {'img': ss}
yzm = getYzm(dict)
print(yzm)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zsheng168/baidudownload.git
git@gitee.com:zsheng168/baidudownload.git
zsheng168
baidudownload
baidudownload
master

搜索帮助