Skip to content

A simple python library to consume the google news rss feed

License

Notifications You must be signed in to change notification settings

LLukas22/Google-News-Feed

Repository files navigation

Google-News-Feed

A simple python library to consume the google news rss feed.

Inspired by pygooglenews and implemented using aiohttp and lxml.

Installation

Via pip: pip install google-news-feed

How to use

from google_news_feed import GoogleNewsFeed

gnf = GoogleNewsFeed(language='en',country='US')
results = gnf.query("python")
print(results)

For more information about the query parameters see here.

Get Top Headlines

gnf = GoogleNewsFeed(language='en',country='US')
results = gnf.top_headlines()

Query a specific topic

gnf = GoogleNewsFeed(language='en',country='US')
results = gnf.query_topic("business")

For more topics see here.

Accessing the results

The results are a list of NewsItems.

result = gnf.query("python")[0]
print(result.title)
print(result.link)
print(result.pubDate)
print(result.description)
print(result.source)

Handling internal links

Some links are internal to google news. To access the actual link to the news site the internal link has to be accessed and the redirect url is returned. To simplify this process the resolve_internal_links property can be set to True.

gnf = GoogleNewsFeed(language='en',country='US',resolve_internal_links=True)
print(gnf.top_headlines()[0].link)

The resolution is handled asynchronously by default, but can be forced to be done synchronously via the run_async parameter.