// //
Html Agility Pack | HAP

Html Agility Pack (HAP) Html Agility Pack


Downloaded more than 200 000 times !
// From File var doc = new HtmlDocument(); doc.Load(filePath); // From String var doc = new HtmlDocument(); doc.LoadHtml(html); // From Web var url = /html-agility-pack.net/"http://html-agility-pack.net/"; var web = new HtmlWeb(); var doc = web.Load(url);
// From File var doc = new HtmlDocument(); doc.Load(filePath); // From String var doc = new HtmlDocument(); doc.LoadHtml(html); // From Web var url = /html-agility-pack.net/"http://html-agility-pack.net/"; var web = new HtmlWeb(); var doc = web.Load(url);



What's Html Agility Pack?

HAP is an HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT.



What's web scraping in C#?

Web scraping is a technique used in any language such as C# to extra data from a website.



Is web scraping legal?

That's a gray zone! There is no official answer about it, and almost every company has some web scraping program. In short, do polite crawling and don't spam a website and everything will be fine.



When is the v2.x coming?

There is no official date, but the work is in progress. A lot of improvement is already planned to make web scraping even easier!



Which 3rd party libraries?

You can enhance HAP with some third party libraries:



Where can I find Html Agility Pack examples?

A lot of examples will be soon available on .NET Fiddle. This feature is under development by our company (ZZZ Projects).

Trusted by thousands around the world!

More than 2000 satisfied customers spreaded across over 75 countries


We had a particularly large (500,000 entities) EF save operations that was taking 12 minutes, this is now down to 30 seconds.

Stewart Menday, Australia, New South Wales

That's really cool! I didn't actually expect you to build a new release in just a day, to be honest, but this is really awesome

Kimwan Ogot, USA, Minneapolis

I would absolutely recommend your product. It is simple, cheap, effective.

HTML Parser

Load and parse HTML

HAP - Parser Example
// From File
var doc = new HtmlDocument();
doc.Load(filePath);

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

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

HTML Selectors

Select HtmlNode, Element, and Attributes:

HAP - 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();

HTML Manipulation

Manipulate HtmlNode, Element, and Attributes:

HAP - Manipulation Example
var doc = new HtmlDocument();
doc.LoadHtml(html);

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

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

HTML Traversing

Traverse HtmlNode, Element, and Attributes:

HAP - Traversing Example
var doc = new HtmlDocument();
htmlDoc.LoadHtml(html);

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

Consulting

Your company requires some custom solution to extend Html Agility Pack with more features?

Contact us to learn about our consultation services:
[email protected]

You can also find some answers/help on: