Skip to content

Instantly share code, notes, and snippets.

@madsc13ntist
Created May 28, 2020 18:07
Show Gist options
  • Select an option

  • Save madsc13ntist/7680766d3132a6cfe5d99c2142d7ae3b to your computer and use it in GitHub Desktop.

Select an option

Save madsc13ntist/7680766d3132a6cfe5d99c2142d7ae3b to your computer and use it in GitHub Desktop.
Just a quick and dirty sample that should help identify how the feedparser module can be used to fetch articles from RSS feeds.
#!/usr/bin/env python3
""""""""" Import Modules """""""""
import feedparser
""""""""" Create a List of RSS feed URLs with articles to fetch """""""""
rss_feed_urls = ["https://www.us-cert.gov/ncas/alerts.xml",
"",
]
""""""""" Walk through your list of rss feed urls """""""""
for rss_feed_url in rss_feed_urls: # For each URL in the list of RSS URLs...
if rss_feed_url not in [[], "", [""], False]: # Make sure that the url isn't empty...
news_feed = feedparser.parse(rss_feed_url) # use feedparser to fetch the RSS content and return it as a dictionary object...
for article in news_feed.entries: # For each "entry" (article) (dict object within the larger dict)....
for key in article.keys(): # For every key in the entry/article's dictionary...
print(f'article["{key}"] = {article[key]}\n') # Print the article's key and matching value.
print("-" * 50) # (Just for easier visual separation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment