0

I have been using this code for months and it has been working perfectly for me but now I am getting this error: Object reference not set to an instance of an object. at this line of code:

Dim Page_Most_Recent_Quarter As Date = document.DocumentNode.SelectSingleNode("//*[@id='financials-iframe-wrap']/div/table//tr[2]/th[3]").InnerText

Here is the full code:

Dim wreq As HttpWebRequest = WebRequest.Create("http://www.nasdaq.com/symbol/GOOG/financials?query=income-statement&data=quarterly")
    wreq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"
    wreq.Method = "get"
    Dim prox As IWebProxy = wreq.Proxy
    prox.Credentials = CredentialCache.DefaultCredentials
    Dim document As New HtmlAgilityPack.HtmlDocument
    Dim web As New HtmlAgilityPack.HtmlWeb
    web.UseCookies = True
    web.PreRequest = New HtmlAgilityPack.HtmlWeb.PreRequestHandler(AddressOf onPreReq)
    wreq.CookieContainer = cookies
    Dim res As HttpWebResponse = wreq.GetResponse()
    document.Load(res.GetResponseStream, True)
    Dim Page_Most_Recent_Quarter As Date = document.DocumentNode.SelectSingleNode("//*[@id='financials-iframe-wrap']/div/table//tr[2]/th[3]").InnerText

I don't think anything has change that would affect this code. I cannot figure out what is wrong.

gromit1
  • 577
  • 2
  • 14
  • 36

1 Answers1

1

I would guess that node does not exist or has been renamed. This is a public website that will make changes to thier stuff on occation. Because it did not find it, it is a NOTHING and you cannot perform a .InnerText on a nothing.

Try putting document.DocumentNode.SelectSingleNode("//*[@id='financials-iframe-wrap']/div/table//tr[2]/th[3]") into another variable and inspect it while debugging.

Steve
  • 5,585
  • 2
  • 18
  • 32
  • When I debug `document.DocumentNode.SelectSingleNode("//*[@id='financials-iframe-wrap']/div/table//tr[2]/th[3]")` it returns as blank. I am very confused because when you look at the webpage, the node is still there and I believe I have the correct syntax. – gromit1 Oct 24 '13 at 17:18
  • 1
    I did look at the HTML of the resulting page and it did look right but I am no expert with the agility pack. You might want to ask that, putting in the resulting HTML, as another question specific to that question. The more info you provide, like the HTML, the more likely you will get someone to look at it. – Steve Oct 24 '13 at 18:16