HTML / VBA Dropdown Menu
Solution 1:
You can isolate the correct dropdown item for selection by combining the id of the parent select
with the attribute = value for the value
attribute of the appropriate child option
tag. The parent select
is expecting an onchange
event which you need to attach and dispatch.
Parent div
by id
and child option
by value
:
Event handler:
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
Solution 2:
The way @QHarr explained is just perfect. Or you can also do something like this with your existing code.
IE.Visible = True
IE.navigate "https://www.betexplorer.com/next/soccer/"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.document
With HTMLDoc.getElementById("next-filter-sort").all(1).all(0)
.Focus
.Value = "2" '"Leagues"
End With
Solution 3:
Sorry both codes work, but how come when I try to extrapolate the name of each league, those are loaded by the "Kick off times" and not by Leagues? he code that I used is:
With IE
.Visible = True
.navigate "https://www.betexplorer.com/next/soccer/"
Do While .readyState <> READYSTATE_COMPLETE
Loop
.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
Do While .readyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.document
End With
i = 9 'Riga di inizio copia dati
j = 0 'Colonna di inizio copia dati
Range("A10:A1005").ClearContents 'Pulisce la Zona dove saranno incollati i dati
Set mycoll = HTMLDoc.getElementsByTagName("TABLE") For Each myItm In mycoll
For Each trtr In myItm.Rows
If trtr.classname = "js-tournament" Then
inizio = InStr(trtr.innerHTML, "href=") + 6
fine = InStr(trtr.innerHTML, "><i") - 1
fedhtml = Trim(Mid(trtr.innerHTML, inizio, fine - inizio))
campionato = Split(Replace(fedhtml, "/soccer/", ""), "/")
campionato = Trim(campionato(1))
Cells(i + 1, j + 1) = trtr.innerText
Cells(i + 1, j + 1).Select
Selection.RowHeight = 15
i = i + 1
End If
Next trtr
Next myItm
Post a Comment for "HTML / VBA Dropdown Menu"