Select Node using XPath is null with HtmlAgilityPack in C# in ASP.Net

Last Reply one month ago By pandeyism

Posted one month ago

I am trying to get element by using x-path tree element but showing null, and this type of x-path work for another site for me, only 2% site this types of X-Path not working.

I tried x-path from chrome also but when my x-path does not work that time chrome x-path also not work

Here is my code.

public static void Main()
{
string url = "http://www.ndrf.gov.in/tender";
HtmlWeb web = new HtmlWeb();
var htmlDoc = web.Load(url);
var nodetest1 = htmlDoc.DocumentNode.SelectSingleNode("/html[1]/body[1]/section[2]/div[1]/div[1]/div[1]/div[1]/div[2]/table[1]"); // i want this type // not wroking
//var nodetest2 = htmlDoc.DocumentNode.SelectSingleNode("//[@id="content"]/div/div[1]/div[2]/table"); // from Google chrome // not wroking
//var nodetest3 = htmlDoc.DocumentNode.SelectSingleNode("//[@id="content"]"); // by ID but i don't want this type // wroking
Console.WriteLine(nodetest1.InnerText); //fail
//Console.WriteLine(nodetest2.InnerText); //fail
//Console.WriteLine(nodetest3.InnerText); //proper but i don't wan't this type
}

 

Posted one month ago

I will get back soon.