Created
May 28, 2020 18:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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