我正在尝试制作一个网络爬虫。我想评估网页是否已加载。
我试过ie.busy 不能正常工作 [VBA]。它第一次起作用。
我将我的 sub 更改为一个函数,并从一个新的 sub 调用此函数,我又遇到了麻烦。
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
它卡在循环中。