【问题标题】:feedparser doesn't give lat long with NOAA xmlfeedparser 没有给出 NOAA xml 的 lat long
【发布时间】:2013-04-02 17:53:32
【问题描述】:

使用NOAA rest 网站上给出的示例网址:

http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?listZipCodeList=20910+25414

以下代码:

import feedparser
d = feedparser.parse('http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?listZipCodeList=20910+25414')
print d

输出:

{'feed': {'dwml': {'xsi:nonamespaceschemalocation': u'http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd', 'nonamespaceschemalocation': u'http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd', 'version': u'1.0'}}, 'status': 200, 'version': u'', 'encoding': u'us-ascii', 'bozo': 0, 'headers': {'content-length': '294', 'expires': 'Wed, 10 Apr 2013 18:16:54 GMT', 'server': 'Apache/2.2.15 (Red Hat)', 'connection': 'close', 'cache-control': 'max-age=180', 'date': 'Wed, 10 Apr 2013 18:13:54 GMT', 'content-type': 'text/xml'}, 'href': u'http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?listZipCodeList=20910+25414', 'namespaces': {u'xsi': u'http://www.w3.org/2001/XMLSchema-instance', u'xsd': u'http://www.w3.org/2001/XMLSchema'}, 'entries': []}

<latLonList> 丢失。我在xml里看到了,为什么feedparser字典里没有呢?

【问题讨论】:

    标签: python xml feedparser noaa


    【解决方案1】:

    feedparser 模块用于解析提要(例如 RSS、ATOM 和 RDF);要解析通用 xml,请尝试 lxml

    这是一个简单的例子

    import urllib
    from lxml import etree
    
    noaa_xml = urllib.urlopen('http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?listZipCodeList=20910+25414').read()
    root = etree.fromstring(noaa_xml)
    print root[0].text
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 2023-03-13
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      相关资源
      最近更新 更多