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
 
I have came across another challenge, please kindly help me out if there is any solution to it.

1727196829146.png


For the column B, in the state of processing it to split it into Home and away teams. I do use the common delimiter which is "-". but this particular league has the "-" included in the name making Left and right function's picks the wrong delimeter when ever there are more than one "-". I noticed that there is always three uppercase before the delimiter "-" e.g B6 has UKS-; B8 has ANI-; B9 has AST- etc. is there a way to split that column into two. with that or a way.

The Vba is #57 is the code I intend to work on but with new Url


Url = https://s5.sir.sportradar.com/sportradar/en/23/season/123235/fixtures

Thanks
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Starting from the code in post #57, I have added a new block, marked as '>>> Block Sep 26 2024, that sets the delimiter to "#"

The new full code:
VBA Code:
Sub SeleniumSportradarManualB409()
'>>> Sep 26 2024
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 TCColl As Object, PosPos As Long
'
'CONFIGURATION:
myUrl = "https://s5.sir.sportradar.com/sportradar/en/23/season/123235/fixtures"     '<<< The web page
''Sheets("Tables").Select                     '<<< The sheet to use    REMOVED, WILL WORK WITH THE ACTIVESHEET
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 = 0
J = Range("A:T").Find(What:="*", After:=Range("A1"), _
              SearchOrder:=xlByRows, _
              SearchDirection:=xlPrevious).Row
On Error GoTo 0
J = J + 2

Stop                                                                          '<<< SELECT THE TAB YOU WISH, THEN "CONTINUE" THE MACRO

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
    '>>>
    Dim iI As Long, jJ As Long
    For iI = 1 To UBound(tArr)
        For jJ = 1 To UBound(tArr, 2)
            If (Len(tArr(iI, jJ)) Mod 2 = 0) And (Len(tArr(iI, jJ)) > 3) Then
                PosPos = InStr(1, tArr(iI, jJ), ":", vbTextCompare)
                If PosPos > 0 And PosPos < 4 And InStr(3, tArr(iI, jJ), Left(tArr(iI, jJ), 3), vbTextCompare) > 0 Then
                    tArr(iI, jJ) = "'" & Left(tArr(iI, jJ), Len(tArr(iI, jJ)) / 2)
                End If
            End If
        Next jJ
    Next iI
    '<<<
    '>>> Block Sep 26 2024
    Set TCColl = TbColl(I).FindElementsByClass("col-xs-12")
    jJ = 2
    For iI = 1 To UBound(tArr)
        If jJ > TCColl.Count Then Exit For
        If Len(tArr(iI, 2)) > 3 Then
             PosPos = InStr(1, tArr(iI, 2), "-" & TCColl(jJ).Text, vbTextCompare)
             If PosPos > 0 Then
                tArr(iI, 2) = Replace(tArr(iI, 2), "-" & TCColl(jJ).Text, " # " & TCColl(jJ).Text, , , vbTextCompare)
                jJ = jJ + 2
             End If
        End If
    Next iI
'<<<
    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...")
WPage.Quit
End Sub
Try...
 
Upvote 1
Starting from the code in post #57, I have added a new block, marked as '>>> Block Sep 26 2024, that sets the delimiter to "#"

The new full code:
VBA Code:
Sub SeleniumSportradarManualB409()
'>>> Sep 26 2024
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 TCColl As Object, PosPos As Long
'
'CONFIGURATION:
myUrl = "https://s5.sir.sportradar.com/sportradar/en/23/season/123235/fixtures"     '<<< The web page
''Sheets("Tables").Select                     '<<< The sheet to use    REMOVED, WILL WORK WITH THE ACTIVESHEET
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 = 0
J = Range("A:T").Find(What:="*", After:=Range("A1"), _
              SearchOrder:=xlByRows, _
              SearchDirection:=xlPrevious).Row
On Error GoTo 0
J = J + 2

Stop                                                                          '<<< SELECT THE TAB YOU WISH, THEN "CONTINUE" THE MACRO

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
    '>>>
    Dim iI As Long, jJ As Long
    For iI = 1 To UBound(tArr)
        For jJ = 1 To UBound(tArr, 2)
            If (Len(tArr(iI, jJ)) Mod 2 = 0) And (Len(tArr(iI, jJ)) > 3) Then
                PosPos = InStr(1, tArr(iI, jJ), ":", vbTextCompare)
                If PosPos > 0 And PosPos < 4 And InStr(3, tArr(iI, jJ), Left(tArr(iI, jJ), 3), vbTextCompare) > 0 Then
                    tArr(iI, jJ) = "'" & Left(tArr(iI, jJ), Len(tArr(iI, jJ)) / 2)
                End If
            End If
        Next jJ
    Next iI
    '<<<
    '>>> Block Sep 26 2024
    Set TCColl = TbColl(I).FindElementsByClass("col-xs-12")
    jJ = 2
    For iI = 1 To UBound(tArr)
        If jJ > TCColl.Count Then Exit For
        If Len(tArr(iI, 2)) > 3 Then
             PosPos = InStr(1, tArr(iI, 2), "-" & TCColl(jJ).Text, vbTextCompare)
             If PosPos > 0 Then
                tArr(iI, 2) = Replace(tArr(iI, 2), "-" & TCColl(jJ).Text, " # " & TCColl(jJ).Text, , , vbTextCompare)
                jJ = jJ + 2
             End If
        End If
    Next iI
'<<<
    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...")
WPage.Quit
End Sub
Try...
It works so perfectly. Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,851
Members
452,675
Latest member
duongtruc1610

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