1

I'm trying to make a web crawler. I want to evaluate if the web page has loaded.

I tried ie.busy not working well [VBA]. It worked the first time.

I changed my sub to be a function, and calling this function from a new sub I'm facing the trouble again.

Public Enum READYSTATE
    READYSTATE_UNINITIALIZED = 0
    READYSTATE_LOADING = 1
    READYSTATE_LOADED = 2
    READYSTATE_INTERACTIVE = 3
    READYSTATE_COMPLETE = 4
End Enum

Function CrawlerNasdaq(strCountry As String) As Double
    
    Dim ie As InternetExplorer
    Dim strURL As String
    Dim x
    
    strURL = "http://www.nasdaqomxnordic.com/indeks/historiske_priser?Instrument=" & strCountry
    
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate strURL

    Do While (ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
        DoEvents
    Loop
    
    Set x = ie.Document.getElementById("historicalTable").getElementsByTagname("tr")(1).getElementsByTagname("td")(6)
    CrawlerNasdaq = x.InnerText
    
    ie.Quit

End Function

Sub HentIndex()
    
    Range("H18") = CrawlerNasdaq("DK0016268840")
    Range("I18") = CrawlerNasdaq("SE0000337842")
    Range("J18") = CrawlerNasdaq("FI0008900212")
    
End Sub

It is stuck in the loop.

Community
  • 1
  • 1
  • 1
    Beyond the function vs. sub procedure problems you are having, if you think about the most efficient way to do this manually, you would never open IE, go to a page for a single piece of information then close IE only to open another IE and repeat the process for an almost identical page. –  Sep 18 '14 at 23:16
  • Yeah your right, that's not very efficient. I will have that in mind :) But that's not what making the problem. – Karsten Jancker Sep 19 '14 at 05:59
  • Okay, this is weird! When I tried the code on my work-PC it wasn't stuck in the loop! On my work-PC I'm using IE 9.0.31 and my IE on my home computer is either IE 10 or IE 11. Does this make any sense at all? – Karsten Jancker Sep 19 '14 at 10:17

0 Answers0