MH Gholizadeh
MH Gholizadeh

Reputation: 15

get all links on a page - HtmlAgilityPack

im trying to get all links(a[href] links) from a web page using HtmlAgilityPack;

my code:

HtmlWeb web = new HtmlWeb();
HtmlDocument site = web.Load("https://www.google.com/");
HtmlNodeCollection links = site.DocumentNode.SelectNodes("//a[@href]");
foreach (HtmlNode link in links)
{
    Console.WriteLine(link.GetAttributeValue("href", "DefaultValue"));   
}

problem: i noticed that my code doesn't getting "all" links from the page and missed some of links...

My result using Jsoup Java

My result using HtmlAgilityPack C#

i did this with JSoup in java and it worked fine.(16 link on google main page) but with HtmlAgilityPack im getting 13 links at the same page... or maybe the problem is on something else... (there is a problem with relative links too but il fix that later)

Upvotes: 1

Views: 757

Answers (0)

Related Questions