Hello Devz,

Sometimes it can be useful to copy a part of the content from a website. That’s where web scraping is useful and HTML Agility Pack is one of the best tools to do it. In this tutorial, I will show you a simple HTML Agility Pack example.

Decide what content you need

Say I wanted to have a list of all the countries in the world along with their country codes. It’s possible to do a quick search, find a website listing them and scrape it for the content. Simply open the web page with C# to get the content, find keywords and scrape the data.

Web scraping with this HTML Agility Pack example

HTML Agility Pack is a free and open source tool that is really useful to get the nodes we want from a web page.

In the below code I show you how to do this HTML Agility Pack example to get the country names and codes:

Note about CSS classes

Of course the way to get the content of a web page will depend on the page itself. This code can’t be generic, but will generally depend on CSS classes name used.

Happy web scraping!  🙂