jkp jkp - 1 year ago 98
HTML Question

How can I instantiate a comment element programatically using lxml?

I'm using lxml to programatically build HTML and I need to include a custom comment in the output. Whilst there is code in lxml to cope with comments (they can be instantiated when parsing existing HTML code) I cannot find a way to instantiate one programatically.

Can anyone help?

Answer Source

You can use the lxml.etree.Comment() factory function. It will return a comment element that you can use like any other element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download