I found a question posted here that had something interesting i wanted to implement in my application.
Previous question(this is using HtmlAgilityPack): Pulling data from a webpage, parsing it for specific pieces, and displaying it
I've done pretty much what they are doing their and i'm getting an error stating object reference not set to an instance of an object. i'm fairly new to programming in general and while I've seen this error message hundreds of times i never seem to understand the cause or how to fix it. Can someone assist with this?
Code:
public void Page_Load()
{
string Url = "myPrivateURL";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(Url);
//Both below strings are getting a null reference exception.
string DeskOncallPhone = doc.DocumentNode.SelectNodes("//*[@id=\"content\"]/div/section/section/div[4]/div[1]/div[1]/div[2]/div/div/div[1]/span")[0].InnerText;
string DeskOncallName = doc.DocumentNode.SelectNodes("//*[@id=\"content\"]/div/section/section/div[4]/div[1]/div[1]/div[2]/div/a[1]")[0].InnerText;
}