GoogleNews Class
GoogleNews
class.
It has 2 required variables: lang
and country
You can try any combination of those 2, however, it does not exist for all. Only
the combinations that are supported by GoogleNews will work. Check the official
Google News page to check what is covered:
On the bottom left side of the Google News page, you may find a
Language & region
section where you can find all of the supported
combinations.
For example, for country=UA
(Ukraine), there are 2 languages supported:
lang=uk
Ukrainianlang=ru
Russian
Top Stories
top_news()
returns the top stories for the selected country and language that
are defined in GoogleNews
class. The returned object contains feed
(FeedParserDict) and entries
list of articles found with all data parsed.
Stories by Topic
feed
(FeedParserDict) and entries
list of
articles found with all data parsed.
Accepted topics are:
WORLD
NATION
BUSINESS
TECHNOLOGY
ENTERTAINMENT
SCIENCE
SPORTS
HEALTH
corona
in the search tab of en
+ US
you
will find COVID-19
as a topic.
The URL looks like this:
https://news.google.com/topics/CAAqIggKIhxDQkFTRHdvSkwyMHZNREZqY0hsNUVnSmxiaWdBUAE?hl=en-US&gl=US&ceid=US%3Aen
We have to copy the text after topics/
and before ?
, then you can use it as
an input for the top_news()
function.
However, be aware that this topic will be unique for each language/country combination.
Stories by Geolocation
feed
(FeedParserDict) and entries
list of
articles found with all data parsed.
All of the above variations will return the same feed of the latest news about
Kyiv, Ukraine:
LA
or
Los Angeles
you can do it with GoogleNews('en', 'US')
.
The main (en
, US
) Google News client will most likely find the feed about
the most places.
Stories by a Query
feed
(FeedParserDict) and entries
list of
articles found with all data parsed.
Google News search itself is a complex function that has inherited some features
from the standard Google Search.
The official reference on what could be inserted
The biggest obstacle that you might have is to write the URL-escaping input. To
ease this process, helper = True
is turned on by default.
helper
uses urllib.parse.quote_plus
to automatically convert the input.
For example:
'New York metro opening'
—>'New+York+metro+opening'
'AAPL -MSFT'
—>'AAPL+-MSFT'
'"Tokyo Olimpics date changes"'
—>'%22Tokyo+Olimpics+date+changes%22'
helper = False
when
parameter (str
) sets the time range for the published datetime. I could
not find any documentation regarding this option, but here is what I deducted:
h
for hours.(For me, worked for up to101h
).when=12h
will search for only the articles matching thesearch
criteria and published for the last 12 hoursd
for daysm
for a amonth (For me, worked for up to48m
)
when
parameter will be ignored by the Google.
from_
and to_
accept the following format of date: %Y-%m-%d
For example,
2020-07-01
Output Body
All 4 functions return thedictionary
that has 2 sub-objects:
feed
- contains the information on the feed metadataentries
- contains the parsed articles
entries
also contains sub_articles
which are the
similar articles found in the description. Usually, it is non-empty for
top_news()
and topic_headlines()
feeds.
Tip To check what is the found feed’s name just check the
title
under the
feed
dictionary