Scrape from webpages without table and classes

Bruzio

Board Regular
Joined
Aug 20, 2020
Messages
85
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Hi to everyone, surfing I found this website BsportsFan It has some interesting data.
The landing pages haven't tables or classes so I wasn't able to get that data. A few months ago @smozgur who I greet, made a vba code for me, I'm still using that sheet, maybe also using this website.
Inspecting the site I found this info:


home.jpg


The destination url is https://app.bsportsfan.com/events/inplay, by clicking on an event i found:

odds.jpg


The destination url is https://app.bsportsfan.com/event/odds?id=3225440.
By changing the id I can find all the data for each event.

My goal is to have this data in a sheet.
I would like to know what tools I need to use.
I apologize if mine are trivial requests.

Thank you for your attention and have a nice day
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Good morning, good news. I understand that it is json script, so I imported VBA-tools/VBA-JSON.
Then I did as written in this post Parse JSON into Excel.

This is the code:

VBA Code:
Sub GET_HOME()

    Dim Request As Object
    Dim url As String
    Dim Response As String
    Dim RunAsync As Boolean
    Dim json As Object
    Dim item As Variant
    Dim i As Long
   
    Set Request = CreateObject("MSXML2.serverXMLHTTP")
 
    url = "https://app.bsportsfan.com/events/inplay"
    RunAsync = True
   
    With Request
        .Open "GET", url, RunAsync 
        .setRequestHeader "Cache-Control", "no-cache"
        .setRequestHeader "Pragma", "no-cache"
        .setRequestHeader "Content-Type", "application/json"
        .send
             
        While Request.readyState <> 4
            DoEvents
        Wend
       
       Response = .responseText
     
    End With
   
    Set json = ParseJson(Response)
 
    i = 2

    For Each item In json("results")

         With Worksheets("home")
            .Range("A" & i).Value = item("id")
            .Range("B" & i).Value = item("league")("name")
            .Range("C" & i).Value = item("home")("name")
            .Range("D" & i).Value = item("away")("name")
            .Range("E" & i).Value = item("ss")
                If item.exists("timer") Then
                    .Range("F" & i).Value = item("timer")("tm")
                End If
        End With
   
    i = i + 1
       
    Next item

    Set Request = Nothing
       
End Sub

This is the result in Excel

IDLEAGUEHOMEAWAYSSTIMER
32321813x3 Liga ProAmur-pro 3x3Zenit-pro 3x33-18
3226516Australian OpenCameron NorrieRoman Safiullin3-6,7-5,6-3,1-1
3223746Australian Open MDBrkic/QureshiAndujar/Martinez6-3,6-7,1-0
3230047ITF M15 St PetersburgArtem DubrivnyyMartin Krumich4-6,6-1,4-4
3229169ITF W15 AntalyaGergana TopalovaPolina Kudermetova6-4,6-7,1-0
3230229ITF W15 VillenaMatilda MutavdzicNicole Fossa Huergo7-5,2-1
3231067DOTA2 - Snow Sweet SnowSpider PigzsCreepwave1-0
3229604Russia Youth LeagueLokomotiv TSIVS YouthUniversitet Nizhnevartovsk Youth23-18
3230721ITF M15 Sharm El SheikhShintaro MochizukiJiri Lehecka2-6,7-6,0-0
2650881Russia MHLAmurskie Tigry U20MHC Spartak U202-314
3230230ITF W15 VillenaRosa Vicens MasLeyre R Gormaz6-4,1-419
3228560ITF W25 GrenobleCristina BucsaAlexandra Eala6-2,3-6,2-2
3230173ITF M15 AntalyaPietro RondoniNerman Fatic6-3,2-6,0-3
3231030ITF W15 AntalyaIrina KhromachevaMarta Custic2-6,4-5
3231984Nepal National League WomenBiratnagar Metropolitan City WomenTribhuvan Army Club Women0-772
3229171ITF W15 AntalyaMatilde PaolettiVlada Koval6-4,3-4
3230065ITF M15 AntalyaKhumoyun SultanovAlvaro Lopez San Martin6-2,5-365
3230778ITF M15 GrenobleMirko MartinezLucas Poullain3-6,1-3
3230339Challenger PotchefstroomUlises BlanchChun Hsin Tseng7-6,1-2
3229538ITF W25 GrenobleTereza MartincovaPemra Ozgen5-6
3227917ITF W25 PotchefstroomGabriela CeAnna Bondar4-6,2-1
3230302ITF M15 MonastirBenjamin PietriOliver Crawford6-4,2-0
3230470ITF W25 PotchefstroomJesika MaleckovaEva Guerrero Alvarez5-6
3230889ITF W25 PotchefstroomAnastasia GasanovaCarolina Meligeni Rodrigues Alves6-3,1-3
3231215ITF W15 Sharm El SheikhFanny OstlundAnna Siskova6-7,0-1
3232076Iran U23 LeagueMes Kerman U23Zob Ahan U230
3230308ITF W15 MonastirMelis YasarLinda Fruhvirtova2-6,2-3
3230221TT Star SeriesJiri VrablikTomas Koldas0-00


I can't do the same thing with https://app.bsportsfan.com/event/odds?id=3172226

error.jpg


Runtime error 13

Please, I'd like to know your opinion about first code and help me for the second link.

Regards
 
Upvote 0
This is the result I would like

BET365
startkickoffend
1_11_21_31_11_21_31_11_21_3
home_oddraw_odaway_odhome_odhandicapaway_odover_odhandicapunder_odhome_oddraw_odaway_odhome_odhandicapaway_odover_odhandicapunder_odhome_oddraw_odaway_odhome_odhandicapaway_odover_odhandicapunder_od
3.2003.3002.1001.9500.0,+0.51.8501.9752.51.8253.1003.1002.3001.875+0.251.9251.8502.251.950301.00051.0001.0022.42501.5255.9004.51.130


I'm spending too many hours and I haven't found the solution yet
 
Upvote 0
item is not a dictionary, so you can't put item("Bet365"). For Each item In json("odds") are the keys inside the "odds" dictionary, which are the betting company names.

Extract the JSON data like this:
VBA Code:
    i = 2
    For Each item In json("odds")
        Debug.Print item
        With Worksheets("odds")
            .Range("A" & i).Value = json("odds")(item)("start")("1_1")("home_od")
            .Range("B" & i).Value = json("odds")(item)("start")("1_1")("draw_od")
            .Range("C" & i).Value = json("odds")(item)("start")("1_1")("away_od")
            i = i + 1
        End With
    Next
 
Upvote 0
Thank you John for your reply. I need to parse just one company name, it's possible?
 
Upvote 0
Don't loop through the company keys then:
VBA Code:
    With Worksheets("odds")
        .Range("A1").Value = json("odds")("Bet365")("start")("1_1")("home_od")
        .Range("B1").Value = json("odds")("Bet365")("start")("1_1")("draw_od")
        .Range("C1").Value = json("odds")("Bet365")("start")("1_1")("away_od")
    End With
 
Upvote 0
Thank you again.
Now, I should parse odds for each id in A column, so this https://app.bsportsfan.com/event/odds?id=3172226 should become https://app.bsportsfan.com/event/odds?id="A4" but how can I set the loop by taking the id column?

Partial final goal

startkickoff
1_11_21_31_11_21_3
home_oddraw_odaway_odhome_odhandicapaway_odover_odhandicapunder_odhome_oddraw_odaway_odhome_odhandicapaway_odover_odhandicapunder_od
3238324Ebasketball Battle - 4x5minsHOU Rockets (Andrik) EsportsUTA Jazz (blaylockk) Esports13-1712,803,062,1420,252
3238326Ebasketball Battle - 4x5minsLA Lakers (Steel) EsportsBOS Celtics (Arthas) Esports8-82
3194358Turkey Efeler LeagueSolhan Metem SporSorgun Bld7-4109
3238373Iceland League 1 WomenKA B WomenYmir Women14-892
3239532Esoccer Battle - 8 mins playBelgium (dm1trena) EsportsBrazil (Foggy) Esports0
3239533Esoccer Battle - 8 mins playPortugal (slezaintima) EsportsFrance (LaikingDast) Esports2
3235859Kenya Super LeagueSoy UnitedAPS Bomet0-088
3222097Romania Liga IChindia TargovisteACS UTA Batrana Doamna1-086
 
Last edited:
Upvote 0
Try this - tests first few IDs. Puts NULL in the cell if an odds value doesn't exist. Add reference to MS XML v6.0.

VBA Code:
Public Sub Get_Odds()

    #If VBA7 Then
        Dim httpReq As XMLHTTP60
        Set httpReq = New XMLHTTP60
    #Else
        Dim httpReq As XMLHTTP
        Set httpReq = New XMLHTTP
    #End If
   
    Dim json As Object
    Dim odds As Object
    Dim r As Long, c As Long, i As Long, j As Long, k As Long
    Dim times As Variant, divs As Variant, oddTypes As Variant
    Dim id As String, company As String
   
    times = Split("start,kickoff", ",")
    divs = Split("1_1,1_2,1_3", ",")
    oddTypes = Split("home_od,draw_od,away_od,home_od,handicap,away_od,over_od,handicap,under_od", ",")
    company = "Bet365"
   
    With Worksheets("Home")
   
        For r = 5 To 10  '.Cells(.Rows.Count, "A").End(xlUp).Row  'test on id rows 5-10
       
            id = .Cells(r, "A").Value
       
            With httpReq
                .Open "GET", "https://app.bsportsfan.com/event/odds?id=" & id, False
                .setRequestHeader "Content-Type", "application/json"
                .send
                Set json = JsonConverter.ParseJson(.responseText)
            End With
           
'            With ThisWorkbook.Worksheets("JSON")
'                .Cells.Clear
'                JSONToCells json, .Range("A1")
'            End With
   
            Set odds = json("odds")
   
            'Start output in column G
            c = 7
                       
            For i = 0 To UBound(times)
                For j = 0 To UBound(divs)
                    For k = 0 To 2
                        Debug.Print .Cells(r, c + i * 9 + j * 3 + k).Address, company, times(i), divs(j), oddTypes(k + j * 3)
                        .Cells(r, c + i * 9 + j * 3 + k).Value = "NULL"
                        If Not IsNull(odds(company)(times(i))) Then
                            If Not IsNull(odds(company)(times(i))(divs(j))) Then
                                If Not IsEmpty(odds(company)(times(i))(divs(j))) Then
                                    .Cells(r, c + i * 9 + j * 3 + k).Value = odds(company)(times(i))(divs(j))(oddTypes(k + j * 3))
                                End If
                            End If
                        End If
                    Next
                Next
            Next
           
            DoEvents
           
        Next

    End With
       
End Sub
 
Upvote 0
Hi John, thank you, the last code returns an error:

Runtime error 424 object required

error424.jpg

JsonConverter is imported
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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