Carl Banks pavlovevidence at gmail.com
Mon Aug 24 13:00:46 CEST 2009

On Aug 24, 12:13 am, Stefan Behnel <stefan... at behnel.de> wrote:
> Hi,
> elsa wrote:
> > I know how to turn HTML into an ElementTree object
> I don't. ;)
> ElementTree doesn't have an HTML parser, so what do you use for parsing?

The OP could be feeding the HTML through tidy, or it could be XHTML.

> > but I don't know
> > how to then view the structure of this object. Is there a method or
> > module that you can give an ElementTree object to, and it returns some
> > kind of graphical or printed representation of the tree? Otherwise, if
> > you can't see you're tree's structure, how do you know what is a
> > sensible way of iterating over the tree to access the info you need?
> ElementTree has a tostring() method that returns a string. To get a pretty
> printed representation, you can use the indent() function from this recipe:
> http://effbot.org/zone/element-lib.htm#prettyprint

Another possibility is to write out the ElementTree object as XML with
an .xml extension, and view it in a modern web browser (Firefox, IE,
others maybe) that can show XML structure.

Carl Banks

More information about the Python-list mailing list