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.