Python feedparser,缺少条目值
我正试图解析来自NOAA的以下RSS源: 除了这一部分外,它工作得很好:Python feedparser,缺少条目值,python,xml,rss,feedparser,Python,Xml,Rss,Feedparser,我正试图解析来自NOAA的以下RSS源: 除了这一部分外,它工作得很好: <item> <title>Summary - Remnants of BARBARA (EP2/EP022013)</title> <guid isPermaLink="false">summary-ep022013-201305302032</guid> <pubDate>Thu, 30 May 2013 20:32
<item>
<title>Summary - Remnants of BARBARA (EP2/EP022013)</title>
<guid isPermaLink="false">summary-ep022013-201305302032</guid>
<pubDate>Thu, 30 May 2013 20:32:00 GMT</pubDate>
<author>nhcwebmaster@noaa.gov (NHC Webmaster)</author>
<link>
http://www.nhc.noaa.gov/text/refresh/MIATCPEP2+shtml/302031.shtml
</link>
<description>
...BARBARA DISSIPATES... ...THIS IS THE LAST ADVISORY... As of 2:00 PM PDT Thu May 30 the center of BARBARA was located at 18.5, -94.5 with movement NNW at 3 mph. The minimum central pressure was 1005 mb with maximum sustained winds of about 25 mph.
</description>
<gml:Point>
<gml:pos>18.5 -94.5</gml:pos>
</gml:Point>
**<nhc:Cyclone>
<nhc:center>18.5, -94.5</nhc:center>
<nhc:type>REMNANTS OF</nhc:type>
<nhc:name>BARBARA</nhc:name>
<nhc:wallet>EP2</nhc:wallet>
<nhc:atcf>EP022013</nhc:atcf>
<nhc:datetime>2:00 PM PDT Thu May 30</nhc:datetime>
<nhc:movement>NNW at 3 mph</nhc:movement>
<nhc:pressure>1005 mb</nhc:pressure>
<nhc:wind>25 mph</nhc:wind>
<nhc:headline>
...BARBARA DISSIPATES... ...THIS IS THE LAST ADVISORY...
</nhc:headline>
</nhc:Cyclone>**
</item>
摘要-巴巴拉遗迹(EP2/EP022013)
汇总表-ep022013-201305302032
2013年5月30日星期四格林尼治标准时间20:32:00
在当前提要XML中,您将看到自定义标记实际上位于条目3中,而不是条目1中。此外,虽然feedparser可以使用自定义标记,但它们被重命名。这在中进行了描述
试试这个(我正在使用feedparser的5.1.2版):
…对于nhc的其他孩子也是如此:Cyclone。我遇到了同样的问题,不确定OP是否解决了这个问题。谢谢你的回答。它实际上是条目4,而不是条目3。非常奇怪。尽管它是一个带有旧日期的示例,但提要似乎已经改变了(因为3以前工作过)。无论如何,很高兴答案对你有用;数组是0索引的。是的,这很有效,我很感激,但后来我发现我遇到的真正问题是一个未修复的bug:
>>> import feedparser
>>> f = feedparser.parse('http://www.nhc.noaa.gov/rss_examples/gis-ep-20130530.xml')
>>> f.entries[1]['description']
u'Shapefile last updated Thu, 30 May 2013 15:03:01 GMT'
>>> f.entries[1]['nhc_cyclone']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "feedparser.py", line 375, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'nhc_cyclone'
>>> f.entries[3].title
u'Summary - Remnants of BARBARA (EP2/EP022013)'
>>> f.entries[3].nhc_center
u'18.5, -94.5'
>>> f.entries[3].nhc_type
u'REMNANTS OF'
>>> f.entries[3].nhc_name
u'BARBARA'