Help Parsing XML Namespaces with BeautifulSoup

snewman18 at gmail.com snewman18 at gmail.com
Sat Feb 17 19:55:15 EST 2007


I'm trying to parse out some XML nodes with namespaces using
BeautifulSoup. I can't seem to get the syntax correct. It doesn't like
the colon in the tag name, and I'm not sure how to refer to that tag.

I'm trying to get the attributes of this tag:

<yweather:forecast day="Sun" date="18 Feb 2007" low="39" high="55"
text="Partly Cloudy/Wind" code="24">

The only way I've been able to get it is by doing a findAll with
regex. Is there a better way?

----------

from BeautifulSoup import BeautifulStoneSoup
import urllib2

url = 'http://weather.yahooapis.com/forecastrss?p=33609'
page = urllib2.urlopen(url)
soup = BeautifulStoneSoup(page)

print soup['yweather:forecast']

----------




More information about the Python-list mailing list