Pregunta

Using the example url given on the NOAA rest site:

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

And the below code:

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

Output:

{'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': []}

The <latLonList> is missing. I see it in the xml, so why isn't it in the feedparser dictionary?

¿Fue útil?

Solución

The feedparser module is for parsing feeds (e.g., RSS, ATOM, and RDF); to parse general xml, try lxml.

Here is a simple example

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top