import urllib.request
import urllib.parse
import json
content=input('请输入需要翻译的内容:')
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=http://www.baidu.com/link'#有道在线翻译的网址
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['typeResult']='true'
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'][0][0]['tgt']))
python--利用有道网址编写一个翻译句子的程序
最新推荐文章于 2022-11-30 11:15:00 发布