tags:

views:

185

answers:

1

xml.etree.ElementTree.parse is choking on my xhtml file. I saw somewhere that lxml can handle html. Can someone tell me the documented way to parse, and then alter, xhtml? I want to add some javascript to xhtml on the fly.

+3  A: 

Have you tried BeautifulSoup? It handles documents that aren't well formed and I've found it pretty good.

Ninefingers
Haven't tried it. Have you parsed xhtml with it?
Alex
Yes - I used in an extractor for data from an xhtml website and it seemed to manage fine. I'm not sure how easy it is to use BeautifulSoup to then edit the document as I've only ever been interested in extraction, but it will handle the extraction part.
Ninefingers