我对VBA和HTML例程有一点问题。我必须从链接https://www.betexplorer.com/next/soccer/中选择“排序方式:”下拉菜单,然后选择“联赛”项。我无法通过VBA执行此操作。
这是我写的代码
Sub Scarica()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLDoc1 As MSHTML.HTMLDocument
Dim Dropdowns As MSHTML.IHTMLElement
Dim post As MSHTML.IHTMLElement
Dim Elem As MSHTML.IHTMLElement
Application.StatusBar = "Download Elenco Campionati odierni in corso..."
Application.ScreenUpdating = False
Application.Calculation = xlManual
IE.Visible = True
IE.navigate "https://www.betexplorer.com/next/soccer/"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
'==================================================
' THIS IS THE PART THAT I CAN'T WRITE
'==================================================
Set HTMLDoc = IE.document
Set post = HTMLDoc.getElementById("wrap-header__list__item.semilong")
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
'==================================================
'==================================================
这是我的第一则消息,我无法插入网站的HTML代码。
您可以通过将父代的IDselect
与相应子标记的属性的attribute = value组合来隔离正确的下拉项以进行选择。家长期待您需要附加和发送的事件。value
option
select
onchange
家长div
通过id
与孩子option
的value
:
事件处理程序:
Option Explicit
Public Sub test()
Dim ie As InternetExplorer, evt As Object
Set ie = New InternetExplorer
With ie
.Visible = True
.Navigate2 "https://www.betexplorer.com/next/soccer/"
While .Busy Or .readyState <> 4: DoEvents: Wend
.document.querySelector("#nr-all [value='2']").Selected = True
Set evt = .document.createEvent("HTMLEvents")
evt.initEvent "change", True, False
.document.querySelector("#nr-all select").dispatchEvent evt
Stop '< delete me later
.Quit
End With
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句