首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >feedparser,缺少条目值

feedparser,缺少条目值
EN

Stack Overflow用户
提问于 2013-06-04 01:19:40
回答 1查看 1.4K关注 0票数 0

我正在尝试解析来自NOAA的以下RSS feed:http://www.nhc.noaa.gov/rss_examples/gis-ep-20130530.xml

除了这一节之外,它工作得很好:

代码语言:javascript
复制
    <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>

feedparser未分析粗体部分。有没有一种方法可以确保在解析中包括自定义标记?

验证:

代码语言:javascript
复制
>>> 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的输出:https://gist.github.com/mustafa0x/6199452

EN

回答 1

Stack Overflow用户

发布于 2013-08-10 19:38:01

在当前的提要XML中,您将看到定制标记实际上位于条目3中,而不是条目1中。此外,尽管feedparser可以使用定制标记,但它们已被重命名。这在http://pythonhosted.org/feedparser/namespace-handling.html中有描述。

试试这个(我使用的是5.1.2版本的feedparser):

代码语言:javascript
复制
>>> 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'

对于nhc的其他子类,旋风也是类似的:...and。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16902286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档