How To Get The Value From A Specific Cell C# Html-Agility-Pack
How do I get a value from a specific location in the second table in the document. I need the value from the second cell down and third column over in the html document below. How
Solution 1:
Html Agility Pack is equipped with an XPATH evaluator that follows .NET XPATH syntax over the parsed HTML nodes. Note the XPATH expression used with this library require elements and attribute names to be lowercase, independently from the original HTML source.
So in your case, you can get the cell for the 3rd column, 2nd row, 2nd table with an expression like this:
HtmlDocument doc = new HtmlDocument();
doc.Load(YouTestHtmlFilePath);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//table[2]/tr[2]/td[3]");
Console.WriteLine(node.InnerText); // will output "4"
//table
means get any TABLE element recursively from root. [2]
means take the 2nd table.
/tr
means get any TR element from this current table. [2]
means take the 2nd row.
/td
means get any TD element from this current row. [3]
means take the 3nd cell.
You can find good XPATH tutorials here: XPath Tutorial
Post a Comment for "How To Get The Value From A Specific Cell C# Html-Agility-Pack"