import urllib.request
import urllib.parse
import json
content = input('请输入要翻译的内容:')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i'] = content
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16518125282681'
data['sign'] = '6692eb68459b9c16e49b4c2fa6e51411'
data['lts'] = '1651812528268'
data['bv'] = '247811f9b7fd387f154bf67d8ebd44f3'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_CLICKBUTTION'
data = urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url,data)
html = response.read().decode('utf-8')
print(html)
target = json.loads(html)
print('翻译结果:%s'%(target['translateResult'][0][0]['tgt']))