Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- 'VBE > Tools > References:
- ' Microsoft Internet Controls
- Public Sub GetOddsInfo()
- Dim ie As New InternetExplorer, url As String, matches()
- Dim i As Long, results(), ws As Worksheet, headers()
- Const MAX_WAIT_SEC As Long = 10
- url = "https://www.oddsportal.com/soccer/norway/norway-cup-women/bryne-gimletroll-6DLVH8pe/#over-under;2"
- Set ws = ThisWorkbook.Worksheets("Plan1")
- headers = Array("Jogo", vbNullString, "Home Odds", "Draw odds", "Away Odds", vbNullString, "BTT", _
- "NBTT", vbNullString, "O2", "U2", vbNullString, "Liga", "Country")
- With ie
- .Visible = True
- matches = Array("https://www.oddsportal.com/soccer/ireland/fai-cup/glebe-north-midleton-K2I3GwFd/")
- ReDim results(1, 1 To 14)
- For i = LBound(matches) To UBound(matches)
- .Navigate2 matches(i) ' default is "#1X2;2"
- While .Busy Or .readyState < 4: DoEvents: Wend
- Dim equipas As String, liga As String, averages As Object, oddH As String, oddD As String, oddA As String
- Dim country As String
- country = vbNullString
- liga = vbNullString
- equipas = vbNullString
- Set averages = .document.querySelectorAll(".aver td")
- oddH = "'" & averages.item(1).innerText 'to ensure odds are correctly formatted on output
- oddD = "'" & averages.item(2).innerText
- oddA = "'" & averages.item(3).innerText
- Set averages = Nothing
- If .document.querySelectorAll("[onclick*='uid\(13\)'], [onmousedown*='uid\(13\)']").Length > 1 Then
- On Error Resume Next
- .document.querySelector("[onclick*='uid\(13\)']").FireEvent "onclick" 'both teams to score
- .document.querySelector("[onmousedown*='uid\(13\)']").FireEvent "onmousedown"
- On Error GoTo 0
- While .Busy Or .readyState < 4: DoEvents: Wend
- Dim oddBtts As String, oddNbtts As String, t As Date
- t = Timer
- Do
- On Error Resume Next
- Set averages = .document.querySelectorAll(".aver td")
- On Error GoTo 0
- If Timer - t > MAX_WAIT_SEC Then Exit Do
- Loop While averages.Length < 2
- If averages.Length > 1 Then
- oddBtts = "'" & averages.item(1).innerText
- oddNbtts = "'" & averages.item(2).innerText
- End If
- Set averages = Nothing
- Else
- oddBtts = "No odds"
- oddNbtts = "No odds"
- End If
- If .document.querySelector("#bettype-tabs li:nth-of-type(5)").getAttribute("style") = "display: block;" Then
- .document.querySelector("#bettype-tabs li:nth-of-type(5) span").FireEvent "onmousedown" 'over/under
- Do
- Loop Until .document.querySelector(".table-chunk-header-dark").getAttribute("style") = "display: block;"
- .document.querySelector("[onclick*='P-2.50-0-0']").Click
- While .Busy Or .readyState < 4: DoEvents: Wend
- Dim oddOver As String, oddUnder As String
- Set averages = .document.querySelectorAll(".aver td")
- oddOver = "'" & averages.item(2).innerText
- oddUnder = "'" & averages.item(3).innerText
- Set averages = Nothing
- Else
- oddOver = "No odds"
- oddUnder = "No odds"
- End If
- Dim resultsPositions(), resultsOrder(), j As Long
- resultsPositions = Array(1, 3, 4, 5, 7, 8, 10, 11, 13, 14) 'columns in output
- resultsOrder = Array(equipas, oddH, oddD, oddA, oddBtts, oddNbtts, oddOver, oddUnder, liga, country)
- For j = LBound(resultsPositions) To UBound(resultsPositions)
- results(i, resultsPositions(j)) = resultsOrder(j)
- Next
- Stop
- equipas = vbNullString: oddH = vbNullString: oddD = vbNullString
- oddA = vbNullString: oddNbtts = vbNullString: oddBtts = vbNullString
- oddOver = vbNullString: oddUnder = vbNullString: liga = vbNullString: country = vbNullString
- 'If i = 5 Then Stop ''for testing
- Next
- Stop
- .Quit
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement