How can I create a comment item programmatically using lxml?

I use lxml to programmatically build HTML, and I need to include a custom comment in the output. Despite the fact that the code in lxml handles comments (they can be created by analyzing existing HTML code), I can’t find a way to create an instance of one programmatically.

Can anyone help?

+4
source share
1 answer

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

+6
source

Source: https://habr.com/ru/post/1285886/


All Articles