|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
'''有道翻译'''
import urllib.request
import urllib.parse
import json
while True:
temp = input('请输入翻译内容:')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
'''
head = {}
head['User-Agent']= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
'''
data = {}
data['i']= temp
data['from']= 'en'
data['to']= 'zh-CHS'
data['smartresult']= 'dict'
data['client']= 'fanyideskweb'
data['salt']= '15846952452571'
data['sign']= '0b637bf91d6e6db786c04d28ebf4abfc'
data['ts']= '1584695245257'
data['bv']= '70244e0061db49a9ee62d341c5fed82a'
data['doctype']= 'json'
data['version']= '2.1'
data['keyfrom']= 'fanyi.web'
data['action']= 'FY_BY_CLICKBUTTION'
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url,data)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36')
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
target = json.loads(html)
print('翻译的结果是:%s'%(target['translateResult'][0][0]['tgt']))
|
|