|
发表于 2017-9-3 16:33:45
|
显示全部楼层
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # @Date : 2017-09-03 16:26:52
- # @Author : Lewis Tian (chasetichlewis@gmail.com)
- # @GitHub : https://github.com/LewisTian
- # @Version : Python3.5
- import requests
- payload = {
- 'i':'',
- 'from':'AUTO',
- 'to':'AUTO',
- 'smartresult':'dict',
- 'client':'fanyideskweb',
- 'salt':'1504427173521',
- 'sign':'18844da9c6c0836b9d75256a31b16e3c',
- 'doctype':'json',
- 'version':'2.1',
- 'keyfrom':'fanyi.web',
- 'action':'FY_BY_REALTIME',
- 'typoResult':'true',
- }
- headers = {
- 'Host':'fanyi.youdao.com',
- 'Referer':'http://fanyi.youdao.com/?keyfrom=dict2.top',
- 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36',
- }
- s = requests.Session()
- def main(word):
- url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
- payload['i'] = word
- r = s.post(url, headers = headers, data = payload)
- tgt = r.json()['translateResult'][0][0]['tgt']
- print(tgt) #browser
- if __name__ == '__main__':
- # word = input()
- main("浏览器")
复制代码
我还是喜欢用requests库 |
|