Scraping data from websites

SHARPY1

Board Regular
Joined
Oct 1, 2007
Messages
183
Hi,

A few years back somebody posted a macro to a betting website that enabled you to download results and fixtures data for any given day from a website called betexplorer.com
I have used this macro for a number of years and found it to be a great tool.
However the website has just gone through a big transformation and obviously something has changed, and the macro no longer works.
I'm guessing for a macro expert it will be a fairly easy fix, but it's beyond me.

If anybody thinks they may be able to help, please let me know.
It will be greatly appreciated

Many thanks
Richard
 
Just wondered is there any way I could run for a date range rather than a single date?
Say 01/12/2016 - 09/12/2016 or is this not possible as it would be several urls?
Would be great if possible.

Cheers
Richard
 
Upvote 0

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.
I've spend enough time on this thread. This is the final change. No more modifications will be entertained after this:

Code:
Option Explicit
Sub Ombir_13Dec16()
Dim i           As Long
Dim j           As Long
Dim rw          As Long
Dim cl          As Long
Dim url         As String
Dim mdate       As String
Dim leagname    As String
Dim matchdate   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 ws          As Worksheet

mdate = InputBox("Enter Match date/dates in dd/mm/yyyy format." & vbCrLf & _
vbCrLf & "For ex :" & vbCrLf & vbCrLf & "14/12/2016" & vbCrLf & vbCrLf & "or" _
& vbCrLf & vbCrLf & "10/12/2016,11/12/2016,12/12/2016,13/12/2016")

If InStr(mdate, ",") Then
    daterng = Split(mdate, ",")
Else
    ReDim daterng(1 To 1)
    daterng(1) = mdate
End If

For Each ele In daterng

    If Not IsDate(ele) Then
        MsgBox "Incorrect Date"
        Exit Sub
    End If
    
    dt = Replace(ele, "/", "-")
    
    On Error Resume Next
    Set ws = ThisWorkbook.Worksheets(dt)
    If ws Is Nothing Then
        ThisWorkbook.Worksheets.Add().Name = dt
        Set ws = ThisWorkbook.Worksheets(dt)
    End If
    On Error GoTo 0
    
    ws.UsedRange.Clear
    Set ie = New InternetExplorer
    url = "http://www.betexplorer.com/results/soccer/?year=" & Split(dt, "-")(2) & "&month=" & Split(dt, "-")(1) & "&day=" & Split(dt, "-")(0)
    
    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-matches js-nrbanner-t")(0).getElementsByTagName("tbody")
    
    ReDim output(1 To leagues.Length * 15, 1 To 11)
    i = 0
    
    For Each league In leagues
        With league
            If .className <> "js-nrbanner-tbody h-display-none" Then
            
                leagname = Application.Clean(.Children(0).innerText)
                matchdate = Doc.getElementsByClassName("in-date-navigation__cal js-window-trigger")(0).innerText
                
                 For rw = 1 To .Rows.Length - 1
                 j = 0
                    If .Rows(rw).className <> "js-newdate" Then
                        i = i + 1: j = j + 1
                        output(i, j) = matchdate
                        output(i, j + 1) = leagname
                        output(i, j + 2) = .Rows(rw).Cells(0).Children(0).innerText
                        output(i, j + 3) = .Rows(rw).Cells(0).Children(1).innerText
                        output(i, j + 4) = Split(output(i, j + 3), "-")(0)
                        output(i, j + 5) = Split(output(i, j + 3), "-")(1)
                        j = 7
                        For cl = 1 To .Rows(rw).Cells.Length - 1
                            output(i, j) = .Rows(rw).Cells(cl).innerText
                            j = j + 1
                        Next
                    Else
                        matchdate = .Rows(rw).innerText
                    End If
                Next
            End If
        End With
    Next
    ie.Quit
    ws.Range("A1:K1") = Array("Date", "League", "Time", "Fixture", "Team1", "Team2", "Col1", "Col2", "Col3", "Col4", "Col5")
    ws.Range("A1:K1").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
Set ws = Nothing
Next
End Sub
 
Upvote 0
Many thanks, much appreciated.
However It doesn't seem to work.
I have tried putting 5 successive dates in 01/12/2-16. 02/12/2016...etc
only gets the 1st date 01/12/2016
then I get Run time error 91
Have you tested it on your machine?

Many thanks
 
Upvote 0
it's ok, it was because I was leaving a space after the comma after each date. no gap now and it works perfectly.
great work, love it, thanks lots :)
 
Upvote 0
Hello Ombir, I hope you're well.
I have been using your macro for 6 months now, and it works great so thank you.

Just wondered if it would be possible to run to get all results for a particular league? (the old macro used to do this)
so as an example the url would be BetExplorer - Premier Division 2017 results & stats

Any help greatly appreciated.
Many thanks
Richard
 
Upvote 0
Hello Ombir, I hope you are well. Not sure if you've seen the above, I sorted that now anyway.
I just needed the initial macro tweaking a little now, as when there is a team that has a "-" in it for eXample Atletico-MG
It automatically puts the home team as Atletico, and the away team as MG instead of Atletico-MG as home team, and the other team as the away team.
It is something to do with the separation caused by the "-" but I can not fathom how to correct it.
Would be great if you could take a look please

Many thanks
 
Upvote 0
Can't say if this is possible because dash(-) is used as a separator between two teams. Share any url with dash in team name to check.
 
Upvote 0
Hi,
Basically, we refer to this website (https://www.mazumamobile.com) for used phone prices. There are two methods to search from a website.
#1 search for a specific phone in search bar #2 Under 'sell my mobile' tab, search by manufacturer.
Second option is better as you don't have to, key in the model no. again and again in search bar, but still need to click on each model to view the prices.

What I want is to get all phone prices, by manufacturer wise, in one excel sheet instead of clicking on each phone model. Please help if its possible? will be good if it gets refreshed every week and only the changes are highlighted.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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