import urllib.request
import urllib.parse
import json
content=input(‘请输入你要翻译文本\n‘)
data={}
data[‘i‘] = content
data[‘from‘] = ‘AUTO‘
data[‘to‘] = ‘AUTO‘
data[‘smartresult‘] = ‘dict‘
data[‘client‘] = ‘fanyideskweb‘
data[‘salt‘] = ‘f‘
data[‘sign‘] = ‘sign‘
data[‘doctype‘] = ‘json‘
data[‘version‘] = ‘2.1‘
data[‘keyfrom‘] = ‘fanyi.web‘
data[‘action‘] = ‘FY_BY_CL1CKBUTTON‘
data[‘typoResult‘] = ‘true‘
url=‘http://fanyi.youdao.com/translate‘
data=urllib.parse.urlencode(data).encode(‘utf-8‘)
request=urllib.request.Request(url=url,data=data)
response=urllib.request.urlopen(request)
html=response.read().decode(‘utf-8‘)
html=json.loads(html)
print(html[‘translateResult‘][0][0][‘tgt‘])