|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import urllib.parse
context = input("请输入您要翻译的中文内容:\n")
result = urllib.parse.quote(context)
url1 = 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=097AF90217CF1BC5B038F01CDE6CA88101A68CBE&oncomplete=translateTexts&from=zh-CN&to=en&text='
url2 = result
url = url1 + url2
data = {}
data['appId'] = '097AF90217CF1BC5B038F01CDE6CA88101A68CBE'
data['oncomplete'] = 'translateTexts'
data['from'] = 'zh-CN'
data['to'] = 'en'
data['text'] = ''
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url,data)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36')
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
print(html[17:-3])
备注翻译器网址:http://www.mutouyu.com/translate.html
|
|