|
|
用的是有道翻译的接口,没有广告和大的程序。全平台拿过来就行。
拿到翻译之后可以自动发音。
- import requests
- import json
- import os
- import yh_dl,yh_os
- def main():
- os.system("cls")
- while True:
- try:
- content = input("请输入:")
- if content == "":
- print("欢迎下次使用")
- break
- headers = {
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0"
- , 'i': content
- , 'from': 'AUTO'
- , 'to': 'AUTO'
- , 'smartresult': 'dict'
- , 'client': 'fanyideskweb'
- , 'salt': '1514345577426'
- , 'sign': '8a12c3bae1619e0d60247aa90a4d945e'
- , 'doctype': 'json'
- , 'version': '2.1'
- , 'keyfrom': 'fanyi.web'
- , 'action': 'FY_BY_REALTIME'
- , 'typoResult': 'false'
- }
- url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=null'
- response = requests.get(url, params=headers)
- html = response.text
- target = json.loads(html)
- #print(html)
- #print(target)
- print()
- jieguo=target['translateResult'][0][0]['tgt']
- print("翻译结果: %s"%jieguo)
- print("="*50)
- print()
- if yh_os.in_txt_chinese(content):
- yh_os.play_txt(jieguo)
- else:
- yh_os.play_txt(content)
- except:
- print('有错误,清除代理重新试一下... ...')
- yh_dl.kill_system_dl()
- if '__main__'==__name__:
- yh_dl.kill_system_dl()
- main()
复制代码
|
|