HAP
Html Agility Pack

Download Count:
3  ,  0 7 6  ,  3 6 3
LOAD &
PARSE HTML
C# HTML Parser Examples
// From File
var htmlDoc = new HtmlDocument();
html.Load(filePath);

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

// From Web
string url = "http://html-agility-pack.net/";
HtmlWeb web = new HtmlWeb();
HtmlDocument document = web.Load(url);
USE
SELECTORS,
TRAVERSORS,
MANIPULATORS,
& MORE
C# HTML Selectors Examples
// With XPath	
string name = htmlDoc.DocumentNode
	.SelectNodes("//td/input")
	.First()
	.Attributes["value"].Value;
	
// With LINQ	
var nodes = htmlDoc.DocumentNode.Descendants("input")
	.Select(y => y.Descendants()
	.Where(x => x.Attributes["class"].Value == "box"))
	.ToList();

 By Millions!

Discover why thousands of developers around the word 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

HTML Parser

Load and parse HTML

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

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

// From Web
string url = "http://html-agility-pack.net/";
HtmlWeb web = new HtmlWeb();
HtmlDocument document = web.Load(url);

HTML Selectors

Select HtmlNode, Element, and Attributes:

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

HTML Manipulation

Manipulate HtmlNode, Element, and Attributes:

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

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

// InnerText	
var innerText = htmlDoc.DocumentNode.InnerText;

HTML Traversing

Traverse HtmlNode, Element, and Attributes:

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

// Descendants	
htmlDoc.DocumentNode.Descendants("input")


More Tutorials & Examples