Hi,
I have this macro, that somebody once did for me, for scraping results from a website called BetExplorer.
It no longer works, as i believe the website may have changed it's layout slightly. Is anybody able to adjust the macro so it works again please?
I get error message: Run-time error '91':
object variable or With block variable not set
I then go to debug and it takes me to the line in macro below that i've highlighted green.
I have this macro, that somebody once did for me, for scraping results from a website called BetExplorer.
It no longer works, as i believe the website may have changed it's layout slightly. Is anybody able to adjust the macro so it works again please?
I get error message: Run-time error '91':
object variable or With block variable not set
I then go to debug and it takes me to the line in macro below that i've highlighted green.
Rich (BB code):
Public Sub newmod()
Dim i As Long
Dim j As Long
Dim rw As Long
Dim cl As Long
Dim num As Long
Dim url As String
Dim mdate As String
Dim leagname As String
Dim cname As String
Dim leg As String
Dim output() As String
Dim dt As String
Dim ele As Variant
Dim daterng As Variant
Dim Doc As HTMLDocument
Dim ie As InternetExplorer
Dim league As HTMLTableSection
Dim leagues As IHTMLElementCollection
Dim leagues1 As HTMLTableSection
Dim ws As Worksheet
Dim k As Long
Dim n As Long
mdate = InputBox("Enter League Name ." & vbCrLf & _
vbCrLf & "For ex :" & vbCrLf & vbCrLf & "ARMENIA: PREMIER-LEAGUE,BRAZIL: SERIE-B")
cname = Split(mdate, ": ")(0)
leg = Split(mdate, ": ")(1)
cname = LCase(cname)
leg = LCase(leg)
ThisWorkbook.Worksheets.Add().Name = cname
Set ws = ThisWorkbook.Worksheets(cname)
On Error GoTo 0
ws.UsedRange.Clear
Set ie = New InternetExplorer
url = "BetExplorer - Soccer statistics - tables, statistics, Soccer results, odds" & cname & "/" & leg & "/results/"
With ie
.Visible = True
.Navigate url
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
End With
Set Doc = ie.document
Set leagues = Doc.getElementsByClassName("table-main h-mb15 js-tablebanner-t js-tablebanner-ntb")(0).getElementsByTagName("tr")
'MsgBox leagues.Length
ReDim output(1 To leagues.Length * 15, 1 To 6)
i = 0
k = 0
n = 3
'MsgBox leagues.Length
Dim text1 As String
For Each league In leagues
With league
text1 = Doc.getElementsByClassName("h-text-center")(n).innerText
j = 0
k = k + 1: j = j + 1
leagname = Doc.getElementsByClassName("in-match")(i).innerText
On Error Resume Next
output(k, j) = Doc.getElementsByClassName("h-text-right h-text-no-wrap")(i).innerText
output(k, j + 1) = mdate
output(k, j + 2) = leagname
output(k, j + 3) = Split(output(k, j + 2), "- ")(0)
output(k, j + 4) = Split(output(k, j + 2), "- ")(1)
If text1 = "1" Or text1 = "X" Or text1 = "2" Then
n = n + 3
text1 = Doc.getElementsByClassName("h-text-center")(n).innerText
output(k, j + 5) = text1
n = n + 1
Else
output(k, j + 5) = text1
n = n + 1
End If
'MsgBox leagname
i = i + 1
'MsgBox text1
End With
Next
ie.Quit
ws.Range("A1:F1") = Array("Date", "League", "Fixture", "Team1", "Team2", "Score")
ws.Range("A1:F1").Interior.ThemeColor = xlThemeColorAccent1
ws.Range("A2").Resize(UBound(output, 1), UBound(output, 2)) = output
With ws.UsedRange
.Columns.AutoFit
.Borders.Weight = xlThin
.WrapText = False
End With
Dim m As Long
For m = 500 To 2 Step -1
If IsEmpty(Range("A" & m)) Then Rows([m]).EntireRow.Delete
Next m
ie.Quit
End Sub
Last edited by a moderator: