Python翻译器
import urllib.requestimport urllib.parse
import json
content='有了我,翻译再也不是问题啦'
print(content)
while content != 'quit':
content=input('请输入需要翻译的内容:')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=https://www.baidu.com/link'
#print(url)
data={}
data['type'] = 'AUTO'
data['i'] = content
data['doctype'] = 'json'
data['xmlVersion'] = '1.8'
data['keyfrom'] = 'fanyi.web'
data['ue'] = 'UTF-8'
data['action'] = 'FY_BY_CLICKBUTTON'
data['typoResult']= 'true'
data = urllib.parse.urlencode(data).encode('utf-8')
#print(data)
response = urllib.request.urlopen(url,data)
html = response.read().decode('utf-8')
#print(html)
target = json.loads(html)
print(target['translateResult'][0][0]['tgt'])
以上是 Python翻译器 的全部内容, 来源链接: utcz.com/z/386721.html