2016-01-21 55 views
1

我們有時差,將採取輸入,例如BOT:是否有從不提供API的網站抓取文本的替代方法?

bible John 3:17 (ESV)

這將變成一個電話

https://www.biblegateway.com/passage/?search=John+3:17&version=ESV

所以,我們已經完蛋了,現在是我們會得到:

curl 'https://www.biblegateway.com/passage/?search=John+3:17&version=ESV' | grep "og:description" | sed 's/.*content="//' | sed 's/".*//' 

For God did not send his Son into the world to condemn the world, but in order that the world might be saved through him. 

這適用於小請求,例如bible John 3:1-4 - 但是,如果我們請求較大的部分,說明字段會在某個點被截斷。因此,如果我們要做bible John 3,它只會返回約翰1的前5個左右的經文。

除了上面的捲曲之外,還有更好的方法可以去解決嗎?在包含全文響應的唯一其他地方是原始的HTML,e.g,:

<h1 class="passage-display"> <span class="passage-display-bcv">John 3</span><span class="passage-display-version">English Standard Version (ESV)</span></h1> [ ... etc. etc. ... ] 

我們是否應該尋找的不僅僅是HTTP這個請求其他的東西嗎?

+1

網站與任何你喜歡的語言,也許Java和JSoup或Python的東西... – Marged

回答

1

如果你想堅持使用oneliner,但是對於你所搜索的內容更精確,你可以試試Mojolicious Perl項目。 Here's an example語法:

perl -Mojo -E 'say g("mojolicious.org")->dom->at("title")->text' 

這將解析出標籤中的文本。對於一行太複雜的任務,請參閱Mojo web scraping example

安裝Mojolicious很簡單:

curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojolicious 

即使你不知道的Perl,你可能可以拼湊您需要爲您的工作刮,作爲DOM遍歷語法可能如果您使用過jQuery,則很熟悉。

+0

所以我感到困惑與刮特定的標記,是這個網站似乎在它有點複雜刮的標籤封裝 - 所以我不知道如何抓住我想要的標籤(或者我猜,*所有*我想要的標籤):http://i.imgur.com/nNLJY​​Sr.png – MrDuk

0

scripture_lookup的CLI非常快速且易於使用。

提供商提供了一個乾淨的界面,可以提供常見的聖經供應商,如Crossways ESV和Bible Gateway。

當前(默認)提供者是BibleGatewayScraper,它從Bible Gateway撤回聖經。

https://github.com/wrightling/scripture_lookup

相關問題