|
|
发表于 2019-1-26 15:46:39
|
显示全部楼层
本帖最后由 jackz007 于 2019-1-26 15:48 编辑
- #!/usr/bin/python
- #coding:gbk
- import requests
- import json
- def get_translate_data(word=None):
- url = 'http://fanyi.youdao.com/translate?smartresulate=dict&smartresulate=rule'
- Form_Data = {'i' : word , 'from' : 'AUTO' , 'to' : 'AUTO' , 'smartresulae' : 'dict' , 'client' : 'fanyideskweb' ,
- 'salt' : '15484256349899' , 'sign' : '21bbe0dec43bb19842ff6ddbd99d3605' , 'ts' : '1548425634989' ,
- 'bv' : '6f014bd66917f921835d1d6ae8073eb1' , 'doctype' : 'json' , 'version' : '2.1' , 'keyfrom' : 'fanyi.web' ,
- 'action' : 'FY_BY_REALTIME' , 'typoResult' : 'false'}
- response = requests . post(url , data = Form_Data)
- content = json . loads(response . text)
- print(content['translateResult'][0][0]['tgt'])
- if __name__ == '__main__':
- get_translate_data('我爱数据')
复制代码
运行环境:python 2.7.13
运行情况:
F:\[2019]\00.00.Exercise\Python\fanyi>python fanyi.py
I love the data
F:\[2019]\00.00.Exercise\Python\fanyi>
楼主可以随时试 |
|