Advertisement
qharr

Untitled

May 3rd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. Option Explicit
  2.  
  3.  
  4. 'VBE > Tools > References:
  5.  
  6. ' Microsoft Internet Controls
  7.  
  8. Public Sub GetOddsInfo()
  9.  
  10. Dim ie As New InternetExplorer, url As String, matches()
  11. Dim i As Long, results(), ws As Worksheet, headers()
  12. Const MAX_WAIT_SEC As Long = 10
  13.  
  14. url = "https://www.oddsportal.com/soccer/norway/norway-cup-women/bryne-gimletroll-6DLVH8pe/#over-under;2"
  15. Set ws = ThisWorkbook.Worksheets("Plan1")
  16. headers = Array("Jogo", vbNullString, "Home Odds", "Draw odds", "Away Odds", vbNullString, "BTT", _
  17. "NBTT", vbNullString, "O2", "U2", vbNullString, "Liga", "Country")
  18. With ie
  19. .Visible = True
  20.  
  21. matches = Array("https://www.oddsportal.com/soccer/ireland/fai-cup/glebe-north-midleton-K2I3GwFd/")
  22. ReDim results(1, 1 To 14)
  23.  
  24. For i = LBound(matches) To UBound(matches)
  25.  
  26. .Navigate2 matches(i) ' default is "#1X2;2"
  27.  
  28. While .Busy Or .readyState < 4: DoEvents: Wend
  29.  
  30. Dim equipas As String, liga As String, averages As Object, oddH As String, oddD As String, oddA As String
  31. Dim country As String
  32.  
  33. country = vbNullString
  34. liga = vbNullString
  35. equipas = vbNullString
  36. Set averages = .document.querySelectorAll(".aver td")
  37. oddH = "'" & averages.item(1).innerText 'to ensure odds are correctly formatted on output
  38. oddD = "'" & averages.item(2).innerText
  39. oddA = "'" & averages.item(3).innerText
  40. Set averages = Nothing
  41.  
  42. If .document.querySelectorAll("[onclick*='uid\(13\)'], [onmousedown*='uid\(13\)']").Length > 1 Then
  43. On Error Resume Next
  44. .document.querySelector("[onclick*='uid\(13\)']").FireEvent "onclick" 'both teams to score
  45. .document.querySelector("[onmousedown*='uid\(13\)']").FireEvent "onmousedown"
  46. On Error GoTo 0
  47.  
  48. While .Busy Or .readyState < 4: DoEvents: Wend
  49.  
  50. Dim oddBtts As String, oddNbtts As String, t As Date
  51.  
  52. t = Timer
  53. Do
  54. On Error Resume Next
  55. Set averages = .document.querySelectorAll(".aver td")
  56. On Error GoTo 0
  57. If Timer - t > MAX_WAIT_SEC Then Exit Do
  58. Loop While averages.Length < 2
  59.  
  60. If averages.Length > 1 Then
  61. oddBtts = "'" & averages.item(1).innerText
  62. oddNbtts = "'" & averages.item(2).innerText
  63. End If
  64. Set averages = Nothing
  65. Else
  66. oddBtts = "No odds"
  67. oddNbtts = "No odds"
  68. End If
  69.  
  70. If .document.querySelector("#bettype-tabs li:nth-of-type(5)").getAttribute("style") = "display: block;" Then
  71.  
  72. .document.querySelector("#bettype-tabs li:nth-of-type(5) span").FireEvent "onmousedown" 'over/under
  73.  
  74. Do
  75. Loop Until .document.querySelector(".table-chunk-header-dark").getAttribute("style") = "display: block;"
  76.  
  77. .document.querySelector("[onclick*='P-2.50-0-0']").Click
  78.  
  79. While .Busy Or .readyState < 4: DoEvents: Wend
  80.  
  81. Dim oddOver As String, oddUnder As String
  82.  
  83. Set averages = .document.querySelectorAll(".aver td")
  84. oddOver = "'" & averages.item(2).innerText
  85. oddUnder = "'" & averages.item(3).innerText
  86. Set averages = Nothing
  87. Else
  88. oddOver = "No odds"
  89. oddUnder = "No odds"
  90. End If
  91.  
  92. Dim resultsPositions(), resultsOrder(), j As Long
  93.  
  94. resultsPositions = Array(1, 3, 4, 5, 7, 8, 10, 11, 13, 14) 'columns in output
  95. resultsOrder = Array(equipas, oddH, oddD, oddA, oddBtts, oddNbtts, oddOver, oddUnder, liga, country)
  96.  
  97. For j = LBound(resultsPositions) To UBound(resultsPositions)
  98. results(i, resultsPositions(j)) = resultsOrder(j)
  99. Next
  100. Stop
  101. equipas = vbNullString: oddH = vbNullString: oddD = vbNullString
  102. oddA = vbNullString: oddNbtts = vbNullString: oddBtts = vbNullString
  103. oddOver = vbNullString: oddUnder = vbNullString: liga = vbNullString: country = vbNullString
  104. 'If i = 5 Then Stop ''for testing
  105. Next
  106. Stop
  107.  
  108. .Quit
  109. End With
  110. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement