Reputation: 153
I am fairly new to the feedparser lib in Python.
Trying to parse out a complete list of timestamps from a RSS feed, I currently have:
import feedparser
from time import gmtime, strftime
d = feedparser.parse('http://www.bloomberg.com/feed/podcast/taking-stock.xml')
dPub = d.entries[0].published # out: u'Mon, 06 May 2013 08:19:36 -0400'
dPubPretty = strftime(dPub, gmtime())
print dPubPretty # out: Mon, 06 May 2013 08:19:36 -0400
# loop over d.entries[0:] - ???
# for all d.entries...
d.entries[1].published # out: u'Mon, 06 May 2013 08:16:15 -0400'
d.entries[2].published # out: u'Fri, 03 May 2013 09:01:50 -0400'
I'd like to loop over all d.entries and output a list of timestamps, so with strftime() applied, the output would be something like:
# output goal:
Mon, 06 May 2013 08:19:36 -0400
Mon, 06 May 2013 08:16:15 -0400
Fri, 03 May 2013 09:01:50 -0400
...
Referencing these docs:
feedparser - Content Normalization: http://pythonhosted.org/feedparser/content-normalization.html#advanced-normalization
time - Time access and conversions: http://docs.python.org/2/library/time.html#time.strftime
Upvotes: 2
Views: 2203
Reputation: 26572
Try to iterate over each entry
import feedparser
from time import gmtime, strftime
d = feedparser.parse('http://www.bloomberg.com/feed/podcast/taking-stock.xml')
for entry in d.entries:
dPub = entry.published
dPubPretty = strftime(dPub, gmtime())
print dPubPretty
You will get the following output:
Mon, 06 May 2013 08:19:36 -0400
Mon, 06 May 2013 08:16:15 -0400
Fri, 03 May 2013 09:01:50 -0400
Fri, 03 May 2013 08:57:55 -0400
Fri, 03 May 2013 08:54:21 -0400
Thu, 02 May 2013 10:04:42 -0400
Thu, 02 May 2013 09:38:42 -0400
...
Mon, 18 Mar 2013 08:03:27 -0400
Mon, 18 Mar 2013 08:01:21 -0400
Upvotes: 2