本帖最后由 小伤口 于 2021-1-1 18:41 编辑 import urllib.request
import urllib.parse
import json
content=input('请输入翻译内容:')
a=[]
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
head={}
head['User-Agent']='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'
data={}
data['i']=content
data['from']='AUTO'
data['to']='AUTO'
data['smartresult']='dict'
data['client']='fanyideskweb'
data['salt']='16079142839884'
data['sign']='7fa30595c70a9a765816fda28b64b9ac'
data['lts']='1607914283988'
data['bv']='4b9de992aa3d23c2999121d735e53f9c'
data['doctype']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_REALTlME'
data=urllib.parse.urlencode(data).encode('utf-8')
req=urllib.request.Request(url,data,head)
response=urllib.request.urlopen(req)
html=response.read().decode('utf-8')
target=json.loads(html)
print(target['translateResult'][0][0]["tgt"])
加一个浏览器访问就可以了head['User-Agent']='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'
把_o去掉 |