from urllib.request import urlopen
from urllib.parse import urlencode
from json import loads
from os import system
while True:
source=input('翻译内容:')
url='http://fanyi.youdao.com/translate'
data={
'i': source,
'type':'AUTO',
'smartresult':'dict',
'doctype':'json',
'version':'2.1',
'keyfrom':'fanyi.web',
'typoResult':'true'
}
data=urlencode(data).encode('utf-8')
response=urlopen(url,data)
html=response.read().decode('utf-8')
html=loads(html)
target=html['translateResult'][0][0]['tgt']#获取json字典中的列表中的字典
print('翻译结果:%s\n' % (target))
system('pause')
网络爬虫之——有道翻译
猜你喜欢
转载自blog.csdn.net/qq_41375702/article/details/88356845
今日推荐
周排行