代码如下,原本执行正常,忽然有一天出现「运行时错误'91':没有设定对象变量或With区块变量」错误,点击侦错,黄底标示在「dd = IE.Document.getElementsByClassName("priceText__1853e8a5")(0).innerText」这行,请问如何修正?谢谢! 注:用IE11开启 https://www.bloomberg.com/quote/USDTWD:CUR 无法正确显示网页。 有人建议改用XMLHTTP抓取,但爬文后仍不得其门而入。
- Sub GetExchangeRate()
- Dim IE As Object
-
- Set IE = CreateObject("InternetExplorer.Application")
- Application.Wait (Now + #12:00:01 AM#)
- IE.Visible = False
- IE.Navigate "https://www.bloomberg.com/quote/USDTWD:CUR"
- Application.StatusBar = "Loading, Please wait..."
- Do While IE.Busy
- Application.Wait DateAdd("s", 1, Now)
- Loop
- Application.StatusBar = "Searching for value. Please wait..."
- Dim dd As Double
- Dim dt As String
- Dim obj As New DataObject
- dd = IE.Document.getElementsByClassName("priceText__1853e8a5")(0).innerText
- dt = IE.Document.getElementsByClassName("time__cbd9bff9")(0).innerText
- obj.SetText (dd)
- obj.PutInClipboard
- MsgBox "USDTWD Spot Exchange Rate: " & dd & vbCrLf & dt
- IE.Visible = False
- IE.Quit
- Set IE = Nothing
- Application.StatusBar = ""
- End Sub
复制代码
|