我对Python中的feedparser lib相当新。
尝试从RSS源解析出完整的时间戳列表,我目前有:
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'
我想循环遍历所有d.entries并输出时间戳列表,因此在应用strftime()时,输出将类似于:
# 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
...
引用这些文档:
feedparser - 内容规范化:http://pythonhosted.org/feedparser/content-normalization.html#advanced-normalization
时间 - 时间访问和转化:http://docs.python.org/2/library/time.html#time.strftime
答案 0 :(得分:2)
尝试迭代每个条目
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
您将获得以下输出:
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