import urllib.requestimport urllib.parseimport jsoncontent = input('请输入需要翻译的内容:')url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict2.index"data = {}data['type'] = 'AUTO'data['i'] = contentdata['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)
添加回答
举报
0/150
提交
取消