user3529857
user3529857

Reputation: 11

Xpath Error: Expression must evaluate to a node-set

I get title in html . And I get Xpath by firebug . But when run, it have error :

Expression must evaluate to a node-set

foreach (HtmlAgilityPack.HtmlNode linkNode in doc.DocumentNode.SelectNodes("/html/body/div/div/div[3]/table/tbody/tr/td[2]/div/table/tbody/tr/td/"))
{
    string imageLink = linkNode.InnerText.Trim();
    richTextBox1.AppendText(imageLink + Environment.NewLine);
}

Upvotes: 1

Views: 4128

Answers (1)

harpo
harpo

Reputation: 43158

Try removing the trailing slash from the XPath expression. It's not valid there.

The slash is basically a shorthand for the child axis. So the expression as you have it is the same as

/html/body/div/div/div[3]/table/tbody/tr/td[2]/div/table/tbody/tr/td/child::

which of course expects another node test. What you mean (I assume) is

/html/body/div/div/div[3]/table/tbody/tr/td[2]/div/table/tbody/tr/td

Upvotes: 2

Related Questions