newscatcher - ニュースサイトに特化したPython製のスクレイピングライブラリ
ニュースサイトは広告が多く、Webブラウザで目的の記事を探すのも面倒です。そのため、RSSフィードを登録している人もいますが、頻繁に訪れるサイトでもなければ、それも面倒です。 そこで使ってみたいのがnewscatcherです。ニュースサイト専用のスクレイピングライブラリです。
newscatcherの使い方
NY Timesのサイトを試す例です。サイトを指定するだけで記事タイトル一覧が取れます。
>>> from newscatcher import Newscatcher
>>> news_source = Newscatcher('nytimes.com')
>>> news_source.print_headlines()
1. | Coronavirus Fears Drive Stocks Down for 6th Day and Into Correction
2. | U.S. Health Workers Responding to Coronavirus Lacked Training and Protective Gear, Whistle-Blower Says
3. | Coronavirus Live Updates: World Reaches ‘Decisive Point’ in Outbreak Fight, W.H.O. Says
4. | Coronavirus Diagnosis in California Highlights Testing Flaws
5. | Home 2, Visitor 1, Spectators 0
さらに、その記事のタイトル、URL、詳細もとれます。
>>> news = news_source.news[0]
>>> news.title
'Coronavirus Fears Drive Stocks Down for 6th Day and Into Correction'
>>> news.link
'https://www.nytimes.com/2020/02/27/business/stock-market-coronavirus.html'
>>> news.description
'The virus, which has now spread to 47 countries, has put pressure on businesses and supply chains around the world.'
newscatcherは一般的なニュースサイトであれば対応しているとのことです。newscatcherを使うことでニュースサイトの最新記事を素早くチェックしたり、URLを得られるようになるでしょう。
newscatcherはPython製のソフトウェア(ソースコードは公開されていますがライセンスは明記されていません)です。
kotartemiy/newscatcher: Programmatically collect normalized news from (almost) any website.