Parsing HTML?

Paul Boddie paul at
Thu Apr 3 15:11:40 CEST 2008

On 3 Apr, 06:59, Benjamin <ben... at> wrote:
> I'm trying to parse an HTML file.  I want to retrieve all of the text
> inside a certain tag that I find with XPath.  The DOM seems to make
> this available with the innerHTML element, but I haven't found a way
> to do it in Python.

With libxml2dom you'd do the following:

 1. Parse the file using libxml2dom.parse with html set to a true
 2. Use the xpath method on the document to select the desired
 3. Use the toString method on the element to get the text of the
    element (including start and end tags), or the textContent
    to get the text between the tags.

See the Package Index page for more details:


More information about the Python-list mailing list