RSS (Really Simple Syndication) feeds are a popular way to get updates from websites in a standardized format. An RSS feed reader can fetch and display the latest entries from an RSS feed, allowing users to stay up-to-date with their favorite websites. In this example, we’ll create a Python script that reads an RSS feed from a given URL and prints the titles and links of the latest entries. We will use the feedparser
library to parse the RSS feed.
import feedparser
def read_rss_feed(feed_url):
feed = feedparser.parse(feed_url)
if feed.bozo:
print("Failed to parse feed. Please check the URL.")
return
print(f"Feed Title: {feed.feed.title}")
print(f"Feed Link: {feed.feed.link}")
print("\nLatest Entries:\n")
for entry in feed.entries[:10]: # Display only the latest 10 entries
print(f"Title: {entry.title}")
print(f"Link: {entry.link}\n")
def main():
print("Welcome to the RSS Feed Reader!")
feed_url = input("Enter the RSS feed URL: ").strip()
read_rss_feed(feed_url)
if __name__ == "__main__":
main()
import feedparser
def read_rss_feed(feed_url):
feed = feedparser.parse(feed_url)
if feed.bozo:
print("Failed to parse feed. Please check the URL.")
return
print(f"Feed Title: {feed.feed.title}")
print(f"Feed Link: {feed.feed.link}")
print("\nLatest Entries:\n")
for entry in feed.entries[:10]: # Display only the latest 10 entries
print(f"Title: {entry.title}")
print(f"Link: {entry.link}\n")
read_rss_feed(feed_url)
feed = feedparser.parse(feed_url)
feedparser.parse()
to fetch and parse the RSS feed from the given URL.if feed.bozo:
checks if there was a problem parsing the feed (e.g., invalid URL or malformed feed).feed.feed.title
and feed.feed.link
.for entry in feed.entries[:10]:
.entry.title
and entry.link
.def main():
print("Welcome to the RSS Feed Reader!")
feed_url = input("Enter the RSS feed URL: ").strip()
read_rss_feed(feed_url)
read_rss_feed(feed_url)
read_rss_feed()
function with the provided URL.