Parse RSS With Python

Python makes it easy to parse an RSS feed. This script parses the RSS feed of this blog, and prints the property of every post.

This script makes use of the Feed Parser module, which you will need to install. If you use Pip, that’s easy:

For Python 2.7

sudo pip install feedparser

For Python 3

sudo pip3 install feedparser

You can read more about Feed Parser here.

This sample Python 3 script parses the RSS feed of this site and returns each post’s title, full URL, and short description.

import feedparser

rss = feedparser.parse('http://www.nextfridayit.com/?feed=rss')

#The site title
channel_title = rss.feed.title
print (channel_title)

#URL of the site
channel_link = rss.feed.link
print (channel_link)

#The site tag
channel_description = rss.feed.description
print (channel_description)

#For every post in the RSS feed....
for entry in rss.entries:
	
	#The title of the post
	entry_title = entry.title
	print (entry_title.encode("ascii", "ignore"))
	
	#A link to the post.
	entry_link = entry.link
	print (entry_link)
	
	#The short description of the post
	entry_description = entry.description
	print (entry_description.encode("ascii", "ignore"))
	
	#The date the post was published
	entry_published = entry.published
	print (entry_published)
	
	

When run, the output looks like this:

$ python3 parse-rss.py
Next Friday
http://nextfridayit.com
Things I do
b'Parse RSS With Python'
Parse RSS With Python
b'Python makes it easy to parse an RSS feed. This script parses the RSS feed of this blog, and prints the property of every post. This script makes use of the Feed Parser module, which you will need to install. If you use Pip, that’s easy: For Python 2.7 For …' Thu, 14 Sep 2017 05:18:15 +0000 b'IP, Port, Referrer & User Agent Lookup Service'
IP, Port, Referrer & User Agent Lookup Service
b'I’ve built a basic IP lookup service, similar to IPEcho.net.I used IPEcho in my May 8 post,Get & Store Your Servers IP Address With PHP. I build on the service by providing other information in friendly JSON format. In addition to your IP, you can access the following programmatically via …' Thu, 31 Aug 2017 18:45:36 +0000