(Solved) – VBA Excel Parsing Odds From Website Problem

(solved)-–-vba-excel-parsing-odds-from-website-problem

i’m trying to learn VBA to parse website informations. Currently i’m trying to parse odds from a website but shows me a error and i don’t know what i’m doing wrong. Can someone help me?
This is my code:

Public Sub GetOddsInfo()
    Dim IE As New InternetExplorer, URL As String
    Dim i As Long, ws As Worksheet
    Dim headers()
    Dim linkgame, linkbtts, linkover As String
    Dim teams, oddHome, oddDraw, oddAway, oddBtts, oddNbtts, oddOver, oddUnder As String
    Const MAX_WAIT_SEC As Long = 10
    URL = "https://www.oddsportal.com/soccer/germany/2-bundesliga/results/#/page/3/"
    Set ws = ThisWorkbook.Worksheets("Plan1")
    headers = Array("Teams", vbNullString, "Home Odds", "Draw Odds", "Away Odds", "BTTS", _
                    "NBTTS", "O2.5", "U2.5")

    With IE
        .Visible = True
        .Navigate2 URL

        While .Busy Or .ReadyState < 4: DoEvents: Wend

        For i = 0 To 1
        '.document.getElementsByClassName(" deactivate").Length -1
            .Navigate2 URL

            linkgame = .document.getElementsByClassName(" deactivate")(i).getElementsByClassName("name table-participant")(0).Children(0).href
            teams = .document.getElementsByClassName(" deactivate")(i).getElementsByClassName("name table-participant")(0).Children(0).innerText

            .Navigate2 linkgame

            oddHome = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(0).innerText
            oddDraw = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(1).innerText
            oddAway = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(2).innerText

            linkbtts = linkgame & "#bts;2"
            .Navigate2 linkbtts

            oddBtts = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(0).innerText
            oddNbtts = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(1).innerText

            linkover = linkgame & "#over-under;2;2.50;0"
            .Navigate2 linkover

            oddOver = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(1).innerText
            oddUnder = .document.getElementsByClassName("aver")(0).getElementsByClassName("right")(2).innerText

            ws.Range("A" & i   2) = teams
            ws.Range("C" & i   2) = oddHome
            ws.Range("D" & i   2) = oddDraw
            ws.Range("E" & i   2) = oddAway
            ws.Range("F" & i   2) = oddBtts
            ws.Range("G" & i   2) = oddNbtts
            ws.Range("H" & i   2) = oddOver
            ws.Range("I" & i   2) = oddUnder
        Next i
    End With
End Sub

Shows me error in .Navigate2 linkgame and i don't understand why since linkgame will be the link of the game.

Leave a Reply

Your email address will not be published. Required fields are marked *