#!/bin/bash
/usr/bin/python <<-EOF
import urllib.request, urllib.parse as parse,json
def youdao(value):
request_url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
form_Data = {'i': value, 'from': 'AUTO', 'to': 'AUTO', 'smartresult': 'dict', 'doctype': 'json', 'version': '2.1',
'keyfrom': 'fanyi.web', 'typoResult': 'false', 'client': 'fanyideskweb'}
data = parse.urlencode(form_Data).encode('utf-8')
trans_res = json.loads(urllib.request.urlopen(request_url, data).read().decode('utf-8'))
show_label = trans_res['translateResult'][0][0]['tgt'] if trans_res.get('translateResult') else ''
return show_label
print("---------------------------")
print("")
print(youdao("${*}")) # 避免需要在待翻译句子两边添加双引号的麻烦
print("")
print("---------------------------")
EOF
2-shell文件 t1 (翻译单词)
#tips:pip(BeautifulSoup4)
#!/bin/bash
/usr/bin/python <<-EOF
import urllib.request, urllib.parse as parse,json
from bs4 import BeautifulSoup
try:
url = "https://dict.youdao.com/w/eng//"
print("---------------------------")
print("")
response = urllib.request.urlopen(url)
content = response.read().decode('utf-8')
soup = BeautifulSoup(content, 'html.parser')
kk=soup.find_all('div',class_='trans-container')
a_T_end=""
for k in kk[0].find_all('li'):
a_T= ''.join(k)
print(a_T)
except:
print("")
print("")
print("---------------------------")
EOF
3-制作命令
- 准备标准shell文件去掉 .sh后缀
- 复制 shell文件到/usr/bin目录下
- chmod 777 [shell文件]
2022-5-9 桃坞
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)