I am trying to get a company's sector on yahoo finance using HTML Agility Pack but I keep getting object reference not set to instance of an object exception. Why does my code throw this exception? I already double checked the xpath Id numerous times.
string Url = "http://www.finance.yahoo.com/q/pr?s=MSFT+Profile";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(Url);
string xpathid = "//*[@id=\"yfncsumtab\"]/tbody/tr[2]/td[1]/table[2]/tbody/tr/td/table/tbody/tr[2]/td[2]/a";
string sector = doc.DocumentNode.SelectNodes(xpathid)[0].InnerText;
Console.WriteLine(sector);
this is the line that is throwing the exception:
string sector = doc.DocumentNode.SelectNodes(xpathid)[0].InnerText;