2

我对 Python 中的 feedparser 库相当陌生。

试图从 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

time - 时间访问和转换:http ://docs.python.org/2/library/time.html#time.strftime

4

1 回答 1

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
于 2013-05-07T08:13:41.760 回答