Genshi for python looks amazing, I hope it infects the rest of python:

>>> html = HTML('''<html> ... <head><title>Some Title</title></head> ... <body> ... Some <em>body</em> text. ... </body> ... </html>''') >>> print html | Transformer('body/em').map(unicode.upper, TEXT) \ ... .unwrap().wrap(tag.u).end() \ ... .select('body/u') \ ... .prepend('underlined ') <html> <head><title>Some Title</title></head> <body> Some <u>underlined BODY</u> text. </body> </html>

i am not a tard.