XPATH utilizing HTML agility pack to extract one td at a time from a tbody

html html-agility-pack xpath


I am trying to parse the table from the URL (Google finance) below


I am trying to extract only the close values in the close column. But when i try with the XPATH


I am getting all the nodes of having attribute as class and value of attribute as rgt in one Node.innerText itself.

I need the values one by one, not all at the same time. I must be doing something silly here. Thank you.

Actual XPath found using Firebug is a follows


But some how after the form tag...HTMLagility pack is returning null node. Never thought this would take so long to implement.

3/6/2011 9:10:26 PM

Accepted Answer

If you're using Firebug or any Firefox extension (like XPather) to obtain the XPath of the elements you need to parse, you might need to remove the tbody tags from the XPath.

Take a look at the following answer here on SO: Why does firebug add <tbody> to <table>?

If you're using HtmlAgilityPack, the XPath returned by Firebug or by any other tool related with Firefox may differ, because the HTML source you're parsing can be different from the HTML source in Firefox.

Sometimes might be useful to open the same page in Internet Explorer 8 and using Developer Tools (F12) do the same you're doing with Firebug, or if not, use another tool like HAP Explorer that can be downloaded from the HtmlAgilityPack page

5/23/2017 12:22:40 PM

Popular Answer

There are many ways to do it. Here is one solution, which is based on the Data td (the one withe the 'lm' class):

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
... load the doc ...

foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//td[@class='lm']/../td[5]"))
    Console.WriteLine("node=" + node.InnerText);

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow