import requests,json,hashlib,time,random
keyword =input("请输入要翻译的内容:")
u ='fanyideskweb'
d = keyword
f =str(int(time.time()*1000) + random.randint(1,10))
c ='ebSeFb%=XZ%T[KZ)c(sy!'
md5 = hashlib.md5()
md5.update(u.encode("gb2312"))
md5.update(d.encode("gb2312"))
md5.update(f.encode("gb2312"))
md5.update(c.encode("gb2312"))
sign = md5.hexdigest()
url ='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
youdao_dic = {
'action':'FY_BY_CLICKBUTTION',
'client':'fanyideskweb',
'doctype':'json',
'from':'AUTO',
'i':keyword,
'keyfrom':'fanyi.web',
'salt':f,
'sign':sign,
'smartresult':'dict',
'to':'AUTO',
'typoResult':'false',
'version':'2.1'
}
res = requests.post(url,data = youdao_dic)
jsonres = json.loads(res.text)
print('翻译结果如下:'+jsonres['translateResult'][0][0]['tgt'])
网友评论