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.
我正在获取一个 URL 并通过调用以下方式获取其所有内容:
CQ dom = ...; string content = dom.Text();
我注意到“Text()”方法还提取了 HTML 注释,例如:
<html> <body> <!-- This is comment - Ignore me --> </body> </html>
我正在寻找一些选项来从代码中删除所有这些注释。像这样的东西:
dom["comment"].remove();
这可能吗?
谢谢
找到了解决方案。
dom的创建应该是这样的:
CQ.Create(stream, Encoding.UTF8, HtmlParsingMode.Auto, HtmlParsingOptions.IgnoreComments);
HtmlParsingOptions.IgnoreComments是我正在寻找的。