I'm following the answer given here: https://stackoverflow.com/a/18066671
string Url = "http://www.owgr.com/ranking"; HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load(Url); string worldRanking = doc.DocumentNode.SelectNodes("//*[@id=\"ranking_table\"]/div/table/tbody/tr/td").InnerText;
But the Xpath is returning a null reference. I've tried several variations but nothing's working, I've never used XPath before, am I missing something?
There is no
<tbody/> element in that table, remove the
/tbody axis step and your query works totally fine. See "Why does my XPath query (scraping HTML tables) only work in Firebug, but not the application I'm developing?" for details.
Additional hint: XPath also supports single quotes for strings, so you don't need to escape the double quotes.
This XPath expression will return the element you're looking for: