Pallavi Kulkarni Pallavi Kulkarni - 1 year ago 103
Python Question

How to obtain field names of RSS feed(xml file) in python dynamically using feedparser?

I have used feedparser library in python to read rss feeds from particlar URL.
the feeds are received in 'fee' variable by using following line of code:

fee = feedparser.parse('')

contains feed in list of list format. The format and the data we get in this is complex and not fixed.

I want to obtain names of fields(keys) of this RSS feed dynamically. How to do that?

some field names are fixed such as link, date etc. But I need names of all fields in my code.

Answer Source
feeds_all =  feedparser.parse('')

I am not sure what kind of json it is, but the functions .keys() and .values() work fine on it. What I did is, for dynamically getting names of keys that are previously unknown (above answer gives static keys and it's values, you need to know the key names in advance), fee.keys() and it worked!

So, the answer is in the following lines: channel_keys = feeds_all.keys() and feed_keys = feeds_all.feed.keys(), for getting value of those keys, feed_values = feeds_all.feed.values()....

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download