|
|

楼主 |
发表于 2018-1-8 22:03:36
|
显示全部楼层
- import urllib.request
- import urllib.parse
- import json
- content = input("输入你要翻译的内容:")
- url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=null'
- head={}
- head['User-Agent']='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
- data={"i":content,
- "from":"AUTO",
- "to":"AUTO",
- "smartresult":"dict",
- "client":"fanyideskweb",
- "salt":"1515412893579",
- "sign":"6932e2a3b985796903e09868378fbb91",
- "doctype":"json",
- "version":"2.1",
- "keyfrom":"fanyi.web",
- "action":"FY_BY_CLICKBUTTION",
- "typoResult": "false"}
- data=urllib.parse.urlencode(data).encode('utf-8')
- req=urllib.request.Request(url,data,head)
- response = urllib.request.urlopen(req)
- html = response.read().decode('utf-8')
- target = json.loads(html)
- print('翻译结果: %s ' % (target['translateResult'][0][0]['tgt']))
复制代码
自己解决啦,希望可以帮到别的小伙伴 |
|