How to Parse Namespaces using the Python RSS Parser?

Getting Ready

Parsing Namespaces

import feedparser

class WhizRssAggregator():
feedurl = ""

def
__init__(self, paramrssurl):
print(paramrssurl)
self.feedurl = paramrssurl
self.parse()

def parse(self):
thefeed = feedparser.parse(self.feedurl)

print("Getting Feed Data")
print(thefeed.feed.get("title", ""))
print(thefeed.feed.get("link", ""))
print(thefeed.feed.get("description", ""))
print(thefeed.feed.get("published", ""))
print(thefeed.feed.get("published_parsed",
thefeed.feed.published_parsed))

for thefeedentry in thefeed.entries:
print("__________")
print(thefeedentry.get("guid", ""))
print(thefeedentry.get("title", ""))
print(thefeedentry.get("link", ""))
print(thefeedentry.get("description", ""))
print("__________")

# Parsing Namespaces
for thefeednamespace in thefeed.namespaces:
if (thefeednamespace == "media"):
# parse for Yahoo Media
print("Media")
allmediacontent = thefeedentry.get("media_content", "")
for themediacontent in allmediacontent:
print(themediacontent["url"])
print(themediacontent["height"])
print(themediacontent["width"])

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store