你用的是旧版接口吗
我照着视频做,用的新版接口,网址和小甲鱼不一样,可是出现了sign和salt这两个动态的参数,照着一个帖子抓取了API可是还是返回{"errorCode":50}
不知道为什么
这是我的代码import urllib.request
import urllib.parse
import time
import random
import hashlib
url='http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link'
u='fanyideskweb'
d='love'
f=str(int(time.time()*1000)+int(random.randint(0,10)))
c="rY0D^0'nM0}g5Mm1z%1G4"
g=hashlib.md5()
g.update((u + d + f + c).encode('utf-8'))
data={}
data['i']=d
data['from']='AUTO'
data['to']='AUTO'
data['smartresult']='dict'
data['client']=u
data['salt']=f
data['sign']=g
data['doctype']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_CL1CKBUTTON'
data['typoResult']='true'
data=urllib.parse.urlencode(data).encode('utf-8')
response=urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')
print(html)
|