Skip to main content
 首页 » 编程设计

python之在 Python 中解析 RSS

2025年05月04日10exmyth

我正在尝试使用 python 解析 rss 提要。

rss 提要的格式为:

 <rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0"> 
      <channel> 
                <title>Yahoo! News - Latest News & Headlines</title> 
                <link>http://news.yahoo.com/</link> 
                <description>...</description> 
                <language>en-US</language> 
                <copyright>Copyright (c) 2013 Yahoo! Inc. All rights reserved</copyright> 
                <pubDate>Thu, 30 May 2013 21:14:41 -0400</pubDate> 
                <ttl>5</ttl> 
                <image>...</image> 
                <item>...</item> 
                <item>...</item> 
                <item>...</item> 
      </channel> 
 </rss> 

我需要提取 <items> 的一些细节.

使用 print feed['channel']['title']等我可以获得那些只发生一次的 block 的详细信息。如何提取项目的详细信息? feed['channel']entries[0]或 feed['channel']['items[0]]等似乎不起作用。

请您参考如下方法:

feed.entries[doc_iter]['title']  

似乎有效。 doc_iter 提到了第 i 项。