代码拉取完成,页面将自动刷新
# 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。