I'm new to creating VBA code and I'm slowly getting a basic understanding of it, however I'm unable to pass this point of my project without assistance. I have the code below and runs great up until I need to continue the code with the new page that opens. I have no idea on how to be able to continue the code and the plan is to be able to click on the odds comparison tab and extract data from that page. Any assistance would be much appreciated.
Sub odd_comparison()
Dim objIE As InternetExplorer
Dim ele As Object
Dim y As Integer
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "http://www.flashscore.com/basketball/"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
objIE.document.getElementById("fs").Children(0) _
.Children(2).Children(2).Children(0).Children(2).Click
End Sub
Try to make loop until the webpage ready as described in this and this answers (you know, replace
WScript.Sleep
withDoEvents
for VBA).Inspect the target element on the webpage with Developer Tools (using context menu or pressing F12). HTML content is as follows:
As you can see there is
onclick
attribute, and actually you can try to execute jscript code from it instead of invokingclick
method:Going further you can find the following spinner element, which appears for the short time while data is being loaded after the tab clicked:
So you can detect when the data loading is completed by checking the visibility state:
The next step is extracting the data you need. You can get all tables from central block:
.document.getElementById("fs").getElementsByTagName("table")
, loop through tables and get all rowsoTable.getElementsByTagName("tr")
, and finally get all cells.getElementsByTagName("td")
andinnerText
.The below example shows how to extract all table data from the webpage odds comparison tab to Excel worksheet:
Webpage odds comparison tab content for me is as follows:
It gives the output: