0

使用NOAA 休息网站上给出的示例 url:

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 字典中?

4

1 回答 1

0

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
于 2013-04-10T18:39:18.600 回答