无限次翻译了 来了
import urllib.requestimport urllib.parse
import json
content=''
def loopstr(content):
while content!='/Q':
content=input('请输入你想要翻译的内容(退出请输入/Q):')
if content=='/Q':
print('退出翻译')
break
if content!='':
tranlatestr(content)
def tranlatestr(str):
url ='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i']=str
data['doctype']='json'
data=urllib.parse.urlencode(data).encode('utf-8')
response=urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')
target = json.loads(html)
print('翻译结果是:%s'%(target['translateResult']['tgt']))
if content!='':
loopstr(content)
else:
loopstr(content)
页:
[1]