Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 lxml 以编程方式构建 HTML,并且需要在输出中包含自定义注释。虽然 lxml 中有处理注释的代码(可以在解析现有 HTML 代码时实例化它们),但我找不到以编程方式实例化注释的方法。
任何人都可以帮忙吗?
You can use the lxml.etree.Comment() factory function. It will return a comment element that you can use like any other element.
lxml.etree.Comment()