RSS and Atom feeds are web feeds. They are written in XML dialects. A web feed is a file used for providing users with frequently updated content, for instance, a list and a summary of the latest published articles on a website.
We can see an excerpt from an RSS feed file in the following widget, written in the RSS v2.0 format. It contains details about the RSS feed such as the _title_
, the _description_
, the _link_
, which is the URL from where the web feed originated. The excerpt contains a single entry that details an online article, _PEP 679_
.
import feedparserfeed = feedparser.parse("https://www.python.org/dev/peps/peps.rss")print('Number of posts in RSS feede :', len(feed.entries))entry = feed.entries[1]print('First post Title :', entry.title)
To parse an RSS or an Atom feed, we will use feedparser
. It’s a universal feed parser and is available on PyPI.
Please use the command pip install feedparser
to install the package.
In the following Python snippet, the program will parse a remote RSS feed, compute the number of entries, and display the title of the first entry.
import feedparserfeed = feedparser.parse("https://www.python.org/dev/peps/peps.rss")print('Number of posts in RSS feede :', len(feed.entries))entry = feed.entries[1]print('First post Title :', entry.title)
Further documentation related to the feedparser API is available here.