HAP
Html Agility Pack

NuGet Download 
Download Count:
LOAD & PARSE HTML
C# HTML Parser Examples
// From File
var doc = new HtmlDocument();
doc.Load(filePath);

// From String
var doc = new HtmlDocument();
doc.LoadHtml(html);

// From Web
var url = "http://html-agility-pack.net/";
var web = new HtmlWeb();
var doc = web.Load(url);
USE SELECTORS, TRAVERSORS, MANIPULATORS, & MORE
C# HTML Selectors Examples
// With XPath	
var value = doc.DocumentNode
.SelectNodes("//td/input")
.First()
.Attributes["value"].Value;

// With LINQ	
var nodes = doc.DocumentNode.Descendants("input")
.Select(y => y.Descendants()
.Where(x => x.Attributes["class"].Value == "box"))
.ToList();

 By Millions!

Discover why thousands of developers around the world use Html Agility Pack

FREE & Open Source

Want to contribute? Access to the full source and help us by providing a pull request.

GitHub

Stack Overflow Support

Have a question? Ask questions and find answers from over 2500 questions.

Stack Overflow

Tutorials & Examples

Need help to getting started? Find answers you need through tutorials and online examples.

Tutorials

Issue Tracker

Found a bug? Have suggestion? Report it and get support from our professional team.

Issues

Getting Started - HTML Agility Pack

 
 
 
1

HTML Parser

Load and parse HTML

Html Parser Tutorials
C# HTML Parser Examples
// From File
var doc = new HtmlDocument();
doc.Load(filePath);

// From String
var doc = new HtmlDocument();
doc.LoadHtml(html);

// From Web
var url = "http://html-agility-pack.net/";
var web = new HtmlWeb();
var doc = web.Load(url);
2

HTML Selectors

Select HtmlNode, Element, and Attributes:

HTML Selectors Tutorials
C# HTML Selectors Examples
// With XPath	
var value = doc.DocumentNode
	.SelectNodes("//td/input")
	.First()
	.Attributes["value"].Value;
	
// With LINQ	
var nodes = doc.DocumentNode.Descendants("input")
	.Select(y => y.Descendants()
	.Where(x => x.Attributes["class"].Value == "box"))
	.ToList();
3

HTML Manipulation

Manipulate HtmlNode, Element, and Attributes:

HTML Manipulation Tutorials
C# HTML Manipulation Examples
var doc = new HtmlDocument();
doc.LoadHtml(html);

// InnerHtml	
var innerHtml = doc.DocumentNode.InnerHtml;

// InnerText	
var innerText = doc.DocumentNode.InnerText;
4

HTML Traversing

Traverse HtmlNode, Element, and Attributes:

HTML Traversing Tutorials
C# HTML Traversing Examples
var doc = new HtmlDocument();
htmlDoc.LoadHtml(html);

// Descendants	
var nodes = doc.DocumentNode.Descendants("input");