python从RSS提要中提取链接

时间:2014-06-21 12:53:11

标签: python

我正在使用http://www.sec.gov/Archives/edgar/monthly/xbrlrss-2012-02.xml的网址,并使用以下命令将其解析为feedparser-5.1.3

g = feedparser.parse('http://www.sec.gov/Archives/edgar/monthly/xbrlrss-2012-02.xml')

如果您转到该网址,您会看到列表中每个链接有多个zip文件

我的目标是找到并提取zip文件的所有链接。

通过在python Shell中输入命令:g['feed'],我得到了提要。

webinar(slide 8)为此目的提供了一些我无法使用的代码。

我在这篇文章中的摘录:

for item in feed.entries:
    print( item[ "summary" ], item[ "title" ], item[ "published" ] )
    try:
        # Identify ZIP file enclosure, if available
        enclosures = [ l for l in item[ "links" ] if l[ "rel" ] == "enclosure" ]

我该怎么做?

1 个答案:

答案 0 :(得分:1)

将名称从g更改为feed,您就可以使用此代码了。