Introduction
The HTML Agility pack is one amazing library that gives a C# developer all the abilities to play with DOM loading and parsing at ease. In order to enter into that comfort zone, it is required for you to first install HTML agility pack since it is minimum that is required to acquaint with its capabilities.HTML Agility Pack Installation
This section walks you through the procedure about how to install HTML agility pack nuget package with simple and lucid words. You could also take help by watching this video where steps are explained in detail.Free Video Library: Learn HTML Agility Pack Step by Step
- First, you can install nuget package from the link.
- Under the section, Package Manager copy the install code. For example, if there is content such as PM> Install-Package HtmlAgilityPack -Version 1.5.1, then you shall copy the text that follows after PM>.
- After copying the code, now go to your Visual Studio Application and click on Tools menu in the menu bar.
- From the menu drop down, go to library manager → Package Manager Console.
- In the lower half of the Application, now you will see the Package Manager Console opened and the cursor blinking.
- You must paste the code that you copied from the site using the help of step:2 by using the combination of hotkeys Ctrl and V.
- After pasting the code hit enter and the application will take care of the installation.
Using the HAP
After successful installation, as an enthusiastic, you would be overwhelmed to learn about how to Load an HTML Document using HTML agility pack or Load DOM using HTML Agility Pack. This section exactly takes care of that. All you will have to do is to follow the below-mentioned steps.Using the HAP
After successful installation, as an enthusiastic, you would be overwhelmed to learn about how to Load an HTML Document using HTML agility pack or Load DOM using HTML Agility Pack. This section exactly takes care of that. All you will have to do is to follow the below-mentioned steps.- First, it is required to add a DLL reference. To do that, you need to go into the Visual Studio Application and press on the Solution Explorer which is located in the sidebar.
- On the Reference text, that you find there, simply right click on it and you need to click on Add Reference, which you will find in the context menu.
- From the Reference Manager window, click on the browser button and point the location in your computer where the HAP dll is present and select it.
- Press Ok. Now come back to the code area of your Visual Studio application and insert the following code, below the list of using statements.
- In the main function, write down the below-given code.
- Save the code and click on Start Button. Hover over the line doc=web.load(“https://technologycrowds.com”); and from the drop down, click on DocumentNode and then press the InnerHtml.
- On the space beside the InnerHtml, click on the search icon and you will be seeing a new window that opens up. The newly loaded window will have all the DOM contents which are nothing but the HTML content of the web page.
HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc = web.load(“https://technologycrowds.com”);
Post A Comment:
0 comments: