【发布时间】:2014-06-18 18:16:17
【问题描述】:
我正在尝试解析 NOAA 天气 RSS 提要。我的脚本可以很好地提取条目,但是有些字段是空白的,我不知道为什么。提要中更复杂的数据类型似乎是一个问题。代码如下:
url = 'http://alerts.weather.gov/cap/us.php?x=1'
feed = feedparser.parse(url)
print 'title: ', feed.entries[0].title
print 'cap_geocode: ', feed.entries[0].cap_geocode
print 'cap_event: ', feed.entries[0].cap_event
以下是打印条目的结果:
title: Flood Watch issued June 18 at 5:00AM AKDT until June 21 at 4:00PM...
cap_geocode:
cap_event: Flood Watch
我不明白为什么 cap_geocode 是空白的。任何的想法?这是只有一个元素的 xml 文件。该提要实际上拉回了 100 个或条目,因此我将其缩减为一个小样本。
<feed
xmlns = 'http://www.w3.org/2005/Atom'
xmlns:cap = 'urn:oasis:names:tc:emergency:cap:1.1'
xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
>
<id>http://alerts.weather.gov/cap/us.atom</id>
<logo>http://alerts.weather.gov/images/xml_logo.gif</logo>
<generator>NWS CAP Server</generator>
<updated>2014-06-18T08:22:00-06:00</updated>
<author>
<name>w-nws.webmaster@noaa.gov</name>
</author>
<title>Current Watches, Warnings and Advisories for the United States Issued by the National Weather Service</title>
<link href='http://alerts.weather.gov/cap/us.atom'/>
<entry>
<id>http://alerts.weather.gov/cap/wwacapget.php?x=WY12515A62F544.WinterWeatherAdvisory.12515A71D320WY.RIWWSWRIW.8dcf1ff2519d541d79867824b0480d63</id>
<updated>2014-06-18T02:57:00-06:00</updated>
<published>2014-06-18T02:57:00-06:00</published>
<author>
<name>w-nws.webmaster@noaa.gov</name>
</author>
<title>Winter Weather Advisory issued June 18 at 2:57AM MDT until June 19 at 12:00AM MDT by NWS</title>
<link href='http://alerts.weather.gov/cap/wwacapget.php?x=WY12515A62F544.WinterWeatherAdvisory.12515A71D320WY.RIWWSWRIW.8dcf1ff2519d541d79867824b0480d63'/>
<summary>...WINTER WEATHER CONTINUES TO IMPACT THE WESTERN AND CENTRAL MOUNTAINS THROUGH MIDNIGHT.</summary>
<cap:event>Winter Weather Advisory</cap:event>
<cap:effective>2014-06-18T02:57:00-06:00</cap:effective>
<cap:expires>2014-06-19T00:00:00-06:00</cap:expires>
<cap:status>Actual</cap:status>
<cap:msgType>Alert</cap:msgType>
<cap:category>Met</cap:category>
<cap:urgency>Expected</cap:urgency>
<cap:severity>Minor</cap:severity>
<cap:certainty>Likely</cap:certainty>
<cap:areaDesc>Absaroka Mountains; Teton and Gros Ventre Mountains</cap:areaDesc>
<cap:polygon></cap:polygon>
<cap:geocode>
<valueName>FIPS6</valueName>
<value>056013 056017 056023 056029 056035 056039</value>
<valueName>UGC</valueName>
<value>WYZ002 WYZ012</value>
</cap:geocode>
<cap:parameter>
<valueName>VTEC</valueName>
<value>/O.CON.KRIW.WW.Y.0031.000000T0000Z-140619T0600Z/</value>
</cap:parameter>
</entry>
</feed>
任何帮助将不胜感激。谢谢
*更新我已经验证 cap_geocode 是一个长度为 0 的空白 unicode 字符串,而不是某种对象。
【问题讨论】:
标签: python xml python-2.7 rss feedparser