马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#coding:utf-8
import urllib.request,urllib.parse
content = input('请输入需要翻译的内容:')
url = 'http://fanyi.baidu.com/v2transapi'
langdetect_url = 'http://fanyi.baidu.com/langdetect'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'
' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
data = {'from': 'en','to': 'zh','simple_means_flag': '3','transtype': 'realtime',
'sign': '124092.329613','token': '3543aae597537a73df19a097215efa55'
}
data['query'] = content
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url,data=data,headers=headers)
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
print(html)
|