Sie können mithilfe der Descendents
Erweiterungsmethode von AngleSharp.Extensions.ApiExtensions
Kommentar-Tags abrufen. Kommentare sind keine Elemente, so dass Sie nicht wie normalerweise nach ihnen suchen können. Mit dieser Erweiterungsmethode können Sie Knoten eines bestimmten Typs abrufen.
IEnumerable<IComment> comments = document.Descendents<IComment>();
Beispiel:
using AngleSharp;
using AngleSharp.Parser.Html;
using AngleSharp.Dom; // For IComment
using AngleSharp.Extensions; // For Descendents
var parser = new HtmlParser();
var source = @"<!-- Single line comment. -->
<!-- Multi-
ple line comment.
Lots '""""' ' "" ` ~ |}{556 of [email protected]#$%^&*()) lines
in
this
comme -
nt!-->";
var document = parser.Parse(source);
// Get all comment nodes
IEnumerable<IComment> comments = document.Descendents<IComment>();
// Get the text in the comment nodes
foreach (IComment comment in comments)
{
var textValue = comment.TextContent;
...
}