我正在努力让excel从网站上刮掉一个价格 https://skrendu.lt/lt/flights/VNOc-OPOc/2016-09-15/1
Sub Macro()
Dim IE As New InternetExplorer
IE.Visible = True
IE.navigate "https://skrendu.lt/lt/flights/VNOc-OPOc/2016-09-15/1"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Application.Wait (Now() + TimeValue("00:00:010"))
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim sTR As String
sTR = Doc.getElementsByClassName("ng-binding ng-scope")(0).innerText
Range(A1) = sTR
IE.Quit
End Sub
但是我得到了错误400.有关为什么不起作用的任何想法?
我在HTML中使用的部分是:
答案 0 :(得分:0)
此代码似乎对我有用。我注意到你错过了A1范围内的"
。
这里有一些工作代码,您可能需要调整等待或设计更好的等待页面加载技术。
Sub FindPrice()
Dim IE As New InternetExplorer
With IE
.Visible = True
.navigate "https://skrendu.lt/lt/flights/VNOc-OPOc/2016-09-15/1"
Application.Wait (Now() + TimeValue("00:00:06")) ' Wait a bit
While .readystate <> READYSTATE_COMPLETE Or .busy
Application.Wait (Now() + TimeValue("00:00:01"))
Wend
Range("A1").Value = IE.document.getElementsByClassName("ng-binding ng-scope")(0).innerText
End With
End Sub