import urllib.request
import urllib.parse
import json
content = input('请输入需要翻译的内容:')
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict2.index"
data = {}
data['type'] = 'AUTO'
data['i'] = content
data['doctype'] = 'json'
data['xmlVetsion'] = '1.6'
data['keyfrom'] = 'fanyi.web'
data['ue'] = 'UTF-8'
data['typoResult'] = 'true'
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url, data)
response = rullib.request.urlopen(req)
html = response.read().decode('utf-8')
target = json.loads(html)
target = target['translateResult'][0][0]['tgt']
print(target)
清波
相关分类