Bin Chen
Bin Chen

Reputation: 63349

python: html writer?

With jquery it's very easy to insert some element inside another element using the selector technology, I am wondering if there is any python library that can do things similar with jquery, the reason is I want server side python program to produce the static pages, which needs to parse the html and insert something into it.

Or other alternative, not in python language at all?

EDIT: To be clear, I want to use python to write below program:

h = html.parse('temp.html')
h.find('#idnum').html('<b>my html generated</b>')

h.close()

Upvotes: 2

Views: 432

Answers (3)

luc
luc

Reputation: 43116

BeautifulSoup can modify the parse tree see http://www.crummy.com/software/BeautifulSoup/documentation.html#Modifying%20the%20Parse%20Tree

Upvotes: 3

Matt V.
Matt V.

Reputation: 9809

It sounds like pyquery works very similarly to what you're looking for.

Upvotes: 3

John La Rooy
John La Rooy

Reputation: 304355

lxml

lxml is a Pythonic binding for the libxml2 and libxslt libraries. It is unique in that it combines the speed and feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API.

Upvotes: 2

Related Questions