[Tutor] html processing

Christopher Arndt chris.arndt at web.de
Sat Dec 2 14:42:26 CET 2006

devayani barve schrieb:
> I have a table in hmtl and i want to write a program so that I
> can insert a column within it..
> Can someone tell me what to use ..... as in dom???
> Just want to know how to go about it!!!

What do you mean exactly? Do you want to manipulate the HTML document in the
browser while displaying it or do you want to change an in-memory
representation of a HTML document (read from and written to a file again perhaps)?

The former would have to be done with JavaScript and you should probably ask on
a JavaScript list how to do this (though I'd highly recommend you look at the
MochiKit JavaScript library <http://mochikit.com/>).

For the latter, you could parse the HTML into a DOM representation and then use
DOM methods to add and change Nodes in it. There are several libraries in
Python that allow you to do so. A recent favourite with the Python community is
ElementTree <http://effbot.org/zone/element.htm>, though you might have to
clean up the HTML input a little bit before you feed it into ElementTree (e.g.
with BeautfulSoup <http://www.crummy.com/software/BeautifulSoup/>.

HTH, Chris

More information about the Tutor mailing list