|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import urllib.parse
import json
while(True):
content = input('请输入要翻译的内容:')
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i'] = content
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = ' dict'
data['client'] = 'fanyideskweb'
data['salt'] = '15558288867571'
data['sign'] = 'ac14af60f7671c19dec2c8f4d89af7a7'
data['ts'] = '1555828886757'
data['bv'] = '94d71a52069585850d26a662e1bcef22'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = ' FY_BY_CLICKBUTTION'
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']))
print('\n')
data = {}是啥意思,如果定义字典的话,不是应该在括号里边吗,还有data['from'] = 'AUTO',只是啥意思,定义字典的一种方式吗
|
|