使用python进行有道翻译
import urllib.request
import urllib.parse
import json
while True:
content = input("please input what you want to translate:(enter quit to quit)")
if content == 'quit':
break
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'] = '15782316731704'
data['sign'] = 'c2bad28143783272b8eec2d481362112'
data['ts'] = '1578231673170'
data['bv'] = 'd6c3cd962e29b66abe48fcb8f4dd7f7d'
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')
#print(html)
target = json.loads(html)
print("translate result is: %s" % (target['translateResult'][0][0]['tgt']))
保存,运行如下: