How To Read Google RSS Feeds In Python

In this article i want to show How To Read Google RSS Feeds In Python, we are using feedparser for this article. so first of all you need to install Feed Parser. you can easily install feedparser using pip command,  pip install feedparser. 

 

 

Also you can check more Python articles in the below links

1: Complete PyQt5 GUI Development Course

2: Python TKinter GUI Development 

3: Psyide2 GUI Development 

4: wxPython GUI Development 

 

 

OK now this is the complete code for How To Read Google RSS Feeds In Python

 

 

 

 

So in the above code we have created a function to fetch the RSS feeds and return the parsed RSS

 

 

 

And this function is for grabbing RSS feed headlines and returns them as a list

 

 

 

Also we need to create an empty list to hold all headlines

 

 

 

OK now this is the RSS Feeds that we want to fetch and combine, basically we are using Google News. but you can change this.

 

 

 

In here we iterate over the feed urls and call the getHeadlines() to combine the returned headlines with allheadlines

 

 

 

And in here we iterate over the allheadlines list an print each headline

 

 

 

 

So now run the complete code and this will be the result

How To Read Google RSS Feeds In Python

 

 

 

 

Also you can watch the video for this article 

Subscribe and Get Free Video Courses & Articles in your Email

 

9 thoughts on “How To Read Google RSS Feeds In Python”

        • import feedparser

          index_number = 0

          def parseRSS( rss_url ):
          return feedparser.parse( rss_url )

          def getHeadlines(rss_url):
          headlines = []

          feed = parseRSS(rss_url)
          for newsitem in feed[‘items’]:
          headlines.append(newsitem[‘title’])

          return headlines

          allheadlines = []

          newsurls = {

          ‘googlenews’: ‘https://news.google.com/news/rss/?hl=en&ned=us&gl=IN’,

          }

          for key, url in newsurls.items():

          allheadlines.extend(getHeadlines(url))

          for hl in allheadlines:
          index_number = index_number + 1
          print(index_number , hl)

    • hey i found a way to add index Numbers in the lines
      i hope it will help you .

      import feedparser

      index_number = 0

      def parseRSS( rss_url ):
      return feedparser.parse( rss_url )

      def getHeadlines(rss_url):
      headlines = []

      feed = parseRSS(rss_url)
      for newsitem in feed[‘items’]:
      headlines.append(newsitem[‘title’])

      return headlines

      allheadlines = []

      newsurls = {

      ‘googlenews’: ‘https://news.google.com/news/rss/?hl=en&ned=us&gl=IN’,

      }

      for key, url in newsurls.items():

      allheadlines.extend(getHeadlines(url))

      for hl in allheadlines:
      index_number = index_number + 1
      print(index_number , hl)

  1. import feedparser

    GoogleFeed = feedparser.parse(“https://news.google.com/rss?hl=pt-BR&ned=br&gl=BR&gl=BR&ceid=BR:pt-419”)

    for entry in GoogleFeed.entries:
    titulo = entry.title
    print (titulo)

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×