AngleSharp – a standards‑compliant HTML parser for .NET
说明与用途
AngleSharp 是一个 .NET 库,实现了 DOM 规范,能够在无浏览器环境下解析 HTML、SVG、MathML、CSS 和 XML。它从一个个人实验成长为广泛使用的组件,下载量超过 5 亿次,应用于清理、测试和渲染等场景。
问题
Developers needed a reliable, spec‑conformant HTML/CSS/JS parser in C# that could be used for scraping, testing, rendering, and sanitization without writing regexes.
结果
AngleSharp grew from a side project into a widely adopted .NET foundation project with over 500 million installs, powering sanitization, testing, email rendering, and many commercial applications.
工作流
- 1. Implement a pure C# HTML5 parser from the spec.
- 2. Add CSS engine and optional JavaScript engine via modular extensions.
- 3. Expose a BrowsingContext API that mimics a browser tab.
- 4. Publish as NuGet packages and open‑source on GitHub.
- 5. Engage community for bug fixes, API improvements, and feature requests.
- 6. Integrate into downstream projects (HtmlSanitizer, bUnit, PreMailer.Net, etc.).
证据
AngleSharp is a .NET library that parses HTML, SVG, MathML, CSS, and (to a good extent) XML, and gives you back a fully-featured, spec-conformant DOM.
The repository already had 120+ stars, and the article was ranking surprisingly well.
AngleSharp 0.10 laid the groundwork for modularity, allowing extensions like CSS and JS to be added as separate libraries.
The core NuGet package alone sits at over 310 million downloads.
HtmlSanitizer uses AngleSharp to parse and re‑render HTML while stripping out anything that could be used for cross‑site scripting.
- 记录日期: 2026-10-02T12:41:07.292Z