SelectNodes returns null

Jan 21, 2012 at 3:26 PM

Hello, I'm a beginner in using HtmlAgilityPack and XPath.

I have download and install the Pack and the Pack Tester. Using the Tester I have gotten an XPath.


My problem is that in my code (see below) SelectSingleNode will always return null when using the xpath that I got from the Tester!

I have tried it in HAP Testbed v 1.1 and it works there so what am I doing wrong?

The code below should set result to "1960"

// Anders

HtmlWeb hw = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = hw.Load("");
string xpath = "/html[1]/body[1]/div[1]/div[5]/div[1]/div[1]/div[3]/table[1]/tr[7]/td[1]";
HtmlNode htmlnode = doc.DocumentNode.SelectSingleNode(xpath);
if (htmlnode != null)
result = htmlnode.InnerText;