4

我正在使用 lxml 以编程方式构建 HTML,并且需要在输出中包含自定义注释。虽然 lxml 中有处理注释的代码(可以在解析现有 HTML 代码时实例化它们),但我找不到以编程方式实例化注释的方法。

任何人都可以帮忙吗?

4

1 回答 1

6

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

于 2009-06-08T06:44:34.097 回答