Cannot pull table from different tabs within the same webpage.

mj sachoo

New Member
Joined
Nov 18, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to obtain the data table from website. However, I can only extract the data from the 'Price' tab.

1605753640023.png


I cannot obtain the tables under the 'Performance', 'Technical and 'Fundamental Tabs.

I get the following error when trying to click the other tabs:

1605753837311.png


I do not know how to get these tables from other tabs.

Last hope is this website as I have not got anything from other forums or websites.

Please advise.

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Having preset the Selenium environment (Selenium basic & browser driver) you should be able to import all the tables presented by that site using the following code:
Code:
Sub SeleniumSportradar()
Dim TbColl As Object, tArr, myItm As Object
Dim I As Long, J As Long, myTim As Single
Dim WPage As Object
Dim myUrl As String
'
'CONFIGURATION:
myUrl = https://s5.sir.sportradar.com/bet9javirtuals/en/1/season/2403775/standings     '<<< The web page
Sheets("Tables").Select                     '<<< The sheet to use
Range("A:T").ClearContents                  '<<< Clear the sheet?
'
myTim = Timer
Set WPage = CreateObject("Selenium.WebDriver")
WPage.Start "Chrome", myUrl                         ' <11
''WPage.Start "edge", myUrl                          ' <22
WPage.Get "/"
'
On Error Resume Next
J = Range("A:T").Find(What:="*", After:=Range("A1"), _
              SearchOrder:=xlByRows, _
              SearchDirection:=xlPrevious).Row
On Error GoTo 0
J = J + 2
Debug.Print vbCrLf & "Start", "J= " & J, WPage.Url, Format(Timer - myTim, "0.00")
Set TbColl = WPage.FindElementsByTag("table")
Debug.Print "Tables found: " & TbColl.Count, Format(Timer - myTim, "0.00")
For I = 1 To TbColl.Count
    Cells(J, 2).Value = "Table #" & I
    tArr = TbColl(I).AsTable.Data
    Cells(J + 1, 1).Resize(UBound(tArr), UBound(tArr, 2)).Value = tArr
    Debug.Print "Table #" & I, UBound(tArr) & " * " & UBound(tArr, 2)
    J = J + UBound(tArr) + 3
Next I
'
Debug.Print "END", I, J, Format(Timer - myTim, "0.00")
WPage.Quit
MsgBox ("Collected...")
End Sub

The main "configuration" is set at the beginning of the macro; see the instructions marked <<<
The same macro should work with any url that presents its data as Tables.

When you are ready, run Sub SeleniumSportradar; it will select the target sheet and clear it (if clear has not been removed); then open a new session of Chrome, read the page, import the tables
 
Upvote 0
The code is not working, says "syntax". Also the last code we run with excel (thread No 14) we created two sheet AAA and BBB so I could import the home and away table separately. this one doesn't have
 
Upvote 0
Please clarify which error you get and on which line.

Also the last code we run with excel (thread No 14) we created two sheet AAA and BBB so I could import the home and away table separately. this one doesn't have
In message #20 I asked "which is the target url and which data should be collected"...
 
Upvote 0
The following macro extract from that page the tables available under the tabs Home matches and Away matches and copy them into the sheets Home and Away:
Code:
Sub SeleniumSportradar()
Dim TbColl As Object, tArr, myItm As Object
Dim I As Long, J As Long, myTim As Single
Dim WPage As Object
Dim myUrl As String
Dim Cycle As Long, tabList
'
'CONFIGURATION:
'
myUrl = "https://s5.sir.sportradar.com/bet9javirtuals/en/1/season/2403775/standings"
tabList = Array("tabs-tab-home", "Home", "tabs-tab-away", "Away")                   '<<< 33
'
myTim = Timer
Set WPage = CreateObject("Selenium.WebDriver")
WPage.Start "Chrome", myUrl                         ' <11
''WPage.Start "edge", myUrl                          ' <22
WPage.Get "/"
'
For Cycle = 0 To UBound(tabList) Step 2
    Sheets(tabList(Cycle + 1)).Select
    Range("A:Z").ClearContents                  'Clear the sheet?
    On Error Resume Next
    J = 0
    J = Range("A:T").Find(What:="*", After:=Range("A1"), _
                  SearchOrder:=xlByRows, _
                  SearchDirection:=xlPrevious).Row
    On Error GoTo 0
    J = J + 2
    Debug.Print "AA", WPage.FindElementById(tabList(Cycle)).Attribute("href"), J
'
    If Cycle = 0 Then           'Force Inspect mode
    WPage.Wait 1000
        Application.SendKeys ("^+i")
        WPage.Wait 1500
        Beep
    End If
    WPage.FindElementById(tabList(Cycle)).Click
'
    WPage.Wait 300
    Debug.Print vbCrLf & "Start", "J= " & J, tabList(Cycle), Format(Timer - myTim, "0.00")
    Set TbColl = WPage.FindElementsByTag("table")
    Debug.Print "Tables found: " & TbColl.Count, Format(Timer - myTim, "0.00")
    For I = 1 To TbColl.Count
        Cells(J, 2).Value = "Table #" & I
        tArr = TbColl(I).AsTable.Data
        Cells(J + 1, 1).Resize(UBound(tArr), UBound(tArr, 2)).Value = tArr
        Debug.Print "Table #" & I, UBound(tArr) & " * " & UBound(tArr, 2)
        J = J + UBound(tArr) + 3
    Next I
Next Cycle
'
Debug.Print "END", I, J, Format(Timer - myTim, "0.00")
WPage.Quit
MsgBox ("Collected...")
End Sub
The code uses the highly-deprecated function SendKeys to open the "inspector window" for Chrome, as this was the only situation that allowed me to click the "non clickable" Home-matches and Away-matches pseudo-links. So do not interact with the pc after the Sub SeleniumSportradar has been started until it is completed or stop in error.

The demo file can be downloaded from my dropbox: SeleniumNSportradar.xlsm
 
Upvote 0
Thank you Anthony, I kept getting and error message, I think it due to chrome stuff. pls I prefer using Edge. thanks.
in another vain, I think the macro is not running differently like it was the other time, that is call 1 for home sheet and call 2 to run for for away sheet.

I'm so sorry for the troubles.
 

Attachments

  • Capture11.JPG
    Capture11.JPG
    21 KB · Views: 8
Upvote 0
Well, thats related to starting Chrome...
You may use Edge, just comment line marked <11 and "un-comment" line marked <22

However Edge gets updated automatically (and I don't know if you can stop that); whenever Edge get updated you probably will need to update the selenium edge driver
 
Upvote 0
Since you wish to pull two tables you can simply create two "Sub Caller": the difference is that Caller1 will specify Sheets("Sheet1"), and you will manually select Home matches; whereas Caller2 will specify Sheets("Sheet2") and you will manually select Away matches
 
Upvote 0

Forum statistics

Threads
1,223,997
Messages
6,175,874
Members
452,679
Latest member
darryl47nopra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top