当前位置:   article > 正文

Python 爬取 有道实时翻译_有道网页上爬声音

有道网页上爬声音
  1. from urllib import request
  2. from urllib import parse
  3. import json
  4. def translate(content):
  5. Request_URL = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
  6. Form_Data = {}
  7. Form_Data['i'] = content
  8. Form_Data['from'] = 'AUTO'
  9. Form_Data['to'] = 'AUTO'
  10. Form_Data['smartresult'] = 'dict'
  11. Form_Data['client'] = 'fanyideskweb'
  12. Form_Data['doctype'] = 'json'
  13. Form_Data['version'] = '2.1'
  14. Form_Data['keyfrom'] = 'fanyi.web'
  15. Form_Data['action'] = 'FY_BY_REALTIME'
  16. Form_Data['typoResult'] = 'false'
  17. data = parse.urlencode(Form_Data).encode('utf-8')
  18. response = request.urlopen(Request_URL, data)
  19. html = response.read().decode('utf-8')
  20. translate_results = json.loads(html)
  21. translate_results = translate_results['translateResult'][0][0]['tgt']
  22. return translate_results
  23. result = translate(input("请输入要翻译的英文:"))
  24. print("翻译的结果是:%s" % result)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/855652
推荐阅读
相关标签
  

闽ICP备14008679号