AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="0.9.4" />

 HtmlParser

public class HtmlParser
Creates an instance of the HTML parser front-end.
using AngleSharp.Dom; using AngleSharp.Dom.Html; using AngleSharp.Extensions; using System.IO; using System.Threading; using System.Threading.Tasks; namespace AngleSharp.Parser.Html { public class HtmlParser { private readonly HtmlParserOptions _options; private readonly IBrowsingContext _context; public HtmlParserOptions Options => _options; public IBrowsingContext Context => _context; public HtmlParser() : this(Configuration.Default) { } public HtmlParser(HtmlParserOptions options) : this(options, Configuration.Default) { } public HtmlParser(IConfiguration configuration) : this(new HtmlParserOptions { IsScripting = configuration.IsScripting() }, configuration) { } public HtmlParser(HtmlParserOptions options, IConfiguration configuration) : this(options, BrowsingContext.New(configuration)) { } public HtmlParser(HtmlParserOptions options, IBrowsingContext context) { _options = options; _context = context; } public IHtmlDocument Parse(string source) { HtmlDocument document = CreateDocument(source); HtmlDomBuilder htmlDomBuilder = new HtmlDomBuilder(document); return htmlDomBuilder.Parse(_options); } public INodeList ParseFragment(string source, IElement context) { HtmlDocument document = CreateDocument(source); HtmlDomBuilder htmlDomBuilder = new HtmlDomBuilder(document); if (context == null) return htmlDomBuilder.Parse(_options).ChildNodes; Element context2 = (context as Element) ?? Factory.HtmlElements.Create(document, context.LocalName, context.Prefix); return htmlDomBuilder.ParseFragment(_options, context2).DocumentElement.ChildNodes; } public IHtmlDocument Parse(Stream source) { HtmlDocument document = CreateDocument(source); HtmlDomBuilder htmlDomBuilder = new HtmlDomBuilder(document); return htmlDomBuilder.Parse(_options); } public Task<IHtmlDocument> ParseAsync(string source) { return ParseAsync(source, CancellationToken.None); } public Task<IHtmlDocument> ParseAsync(Stream source) { return ParseAsync(source, CancellationToken.None); } public async Task<IHtmlDocument> ParseAsync(string source, CancellationToken cancel) { HtmlDocument document = CreateDocument(source); HtmlDomBuilder parser = new HtmlDomBuilder(document); return await parser.ParseAsync(_options, cancel).ConfigureAwait(false); } public async Task<IHtmlDocument> ParseAsync(Stream source, CancellationToken cancel) { HtmlDocument document = CreateDocument(source); HtmlDomBuilder parser = new HtmlDomBuilder(document); return await parser.ParseAsync(_options, cancel).ConfigureAwait(false); } private HtmlDocument CreateDocument(string source) { TextSource textSource = new TextSource(source); return CreateDocument(textSource); } private HtmlDocument CreateDocument(Stream source) { TextSource textSource = new TextSource(source, _context.Configuration.DefaultEncoding()); return CreateDocument(textSource); } private HtmlDocument CreateDocument(TextSource textSource) { return new HtmlDocument(_context, textSource); } } }