質問は、〜/ .bashrcの
にこの行をすることができ、実行可能
としてメイクスクリプト
プログラムは のpython3のdefineterm.pyリンゴを開始することができ
#! /usr/bin/env python3.5
# defineterm.py
import requests
from bs4 import BeautifulSoup
import sys
import html
import codecs
searchterm = ' '.join(sys.argv[1:])
url = 'https://www.google.com/search?q=define+' + searchterm
res = requests.get(url)
try:
res.raise_for_status()
except Exception as exc:
print('error while loading page occured: ' + str(exc))
text = html.unescape(res.text)
soup = BeautifulSoup(text, 'lxml')
prettytext = soup.prettify()
#next lines are for analysis (saving raw page), you can comment them
frawpage = codecs.open('rawpage.txt', 'w', 'utf-8')
frawpage.write(prettytext)
frawpage.close()
firsttag = soup.find('h3', class_="r")
if firsttag != None:
print(firsttag.getText())
print()
#second tag may be changed, so check it if not returns correct result. That might be situation for all searched tags.
secondtag = soup.find('div', {'style': 'color:#666;padding:5px 0'})
if secondtag != None:
print(secondtag.getText())
print()
termtags = soup.findAll("li", {"style" : "list-style-type:decimal"})
count = 0
for tag in termtags:
count += 1
print(str(count)+'. ' + tag.getText())
print()
いいアイデアです追加
alias defterm="/data/Scrape/google/defineterm.py "
その後、
実行するあなたの場所のスクリプトに正しいパスを入れ
source ~/.bashrc
プログラムが使用を開始することができます:あなただけの
defterm apple (or other term)
ありがとうございましたので、答えとも 'deftermのために非常に多くの'スクリプト。私は今それをテストしています。私は毎日の投票限度額を使いましたが、私はあなたにふさわしい投票をするために2時間後に戻ってきます:Dまた、私は 'defterm'スクリプトを修正してGithubに再度載せることを許可しますありがとうございました。 –
Pythonスクリプトとdeftermの問題はありません。 – josifoski