scrape sportinglife using Excel VBA

Please post any questions regarding the program here.

Moderator: 2020vision

scrape sportinglife using Excel VBA

Postby youngstar » Sun Jun 05, 2016 12:41 pm

I'm trying to scrape race card info from Sporting life.
Currently, I'm able to get hold of the links for each race and extract the time & track using Excel VBA.

I want to be able to extract each runner's name and specifically the "BF" info for each runner (whether it
was a beaten favourite). :roll:

Anyone doing this at the moment?


Thanks
Young
youngstar
 
Posts: 7
Joined: Fri Nov 15, 2013 2:07 pm

Re: scrape sportinglife using Excel VBA

Postby alrodopial » Mon Jun 06, 2016 11:39 am

It's element has class name "rp-cdwf"
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm

Re: scrape sportinglife using Excel VBA

Postby youngstar » Mon Jun 06, 2016 8:42 pm

Al

Do you have the code to extract the runner's name and whether BF.
I can't find "rp-cdwf" in the source code when I open a race card in Sportinglife :oops:


Thanks
youngstar
 
Posts: 7
Joined: Fri Nov 15, 2013 2:07 pm

Re: scrape sportinglife using Excel VBA

Postby alrodopial » Mon Jun 06, 2016 8:56 pm

Give me a couple of days
It's class name is "sui enable-tooltip sui-bf"
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm

Re: scrape sportinglife using Excel VBA

Postby youngstar » Mon Jun 06, 2016 9:08 pm

ok, thanks in advance.
:)
youngstar
 
Posts: 7
Joined: Fri Nov 15, 2013 2:07 pm

Re: scrape sportinglife using Excel VBA

Postby MiniBlueDragon » Tue Jun 07, 2016 3:16 pm

Would something like this work? (not checked it)
Code: Select all
Set iDocElements = iDoc.getElementsByClassName("horse-dtl")

   For Each iElement In iDocElements
                  
      ' Get Runner Name
      runnerName = iElement.Children(1).innerText
      runnerName = Replace(Replace(Replace(Trim(runnerName), " ", " |"), "| ", ""), " |", " ")
      
      ' Strip Country info            
      j = InStr(runnerName, "(")
      If j > 0 Then runnerName = Trim(Left(runnerName, j - 1))
      
      Set bfElements = iElement.getElementsByClassName("sui enable-tooltip sui-bf")
      
      If bfElements.length > 0 Then
         beatenFav = 1
      End If
      
      myRow = myRow + 1
      
   Next
MiniBlueDragon
 
Posts: 130
Joined: Tue Jul 05, 2011 1:14 pm
Location: London

Re: scrape sportinglife using Excel VBA

Postby alrodopial » Tue Jun 07, 2016 3:46 pm

MiniBlueDragon wrote:Would something like this work? (not checked it)
Code: Select all
Set iDocElements = iDoc.getElementsByClassName("horse-dtl")

   For Each iElement In iDocElements
                  
      ' Get Runner Name
      runnerName = iElement.Children(1).innerText
      runnerName = Replace(Replace(Replace(Trim(runnerName), " ", " |"), "| ", ""), " |", " ")
      
      ' Strip Country info            
      j = InStr(runnerName, "(")
      If j > 0 Then runnerName = Trim(Left(runnerName, j - 1))
      
      Set bfElements = iElement.getElementsByClassName("sui enable-tooltip sui-bf")
      
      If bfElements.length > 0 Then
         beatenFav = 1
      End If
      
      myRow = myRow + 1
      
   Next



It looks ok to me
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm

Re: scrape sportinglife using Excel VBA

Postby youngstar » Wed Jun 08, 2016 9:25 pm

I'm getting "run-time error '424': Object required" on the first line!

Set iDocElements = iDoc.getElementsByClassName("horse-dtl")
youngstar
 
Posts: 7
Joined: Fri Nov 15, 2013 2:07 pm

Re: scrape sportinglife using Excel VBA

Postby alrodopial » Thu Jun 09, 2016 5:29 pm

copy paste the below in a module and run the macro
Adjust the "goURL"

Code: Select all
Dim goURL As String
Dim IE1 As Object
Dim IEdoc1 As MSHTML.HTMLDocument

Sub openURL_IE1()
   
    If IE1 Is Nothing Then
        Set IE1 = CreateObject("InternetExplorer.Application")
        IE1.Visible = True
    End If
    Application.StatusBar = "Loading page ... " & goURL
    IE1.Navigate goURL
    Do While IE1.Busy Or IE1.ReadyState <> 4: DoEvents: Loop
    Application.StatusBar = False
   
    Set IEdoc1 = IE1.document
   
End Sub

Sub getBFfromSLcard()
   
    Set ws1 = ThisWorkbook.Sheets("Sheet1")
   
    goURL = "http://www.sportinglife.com/racing/meeting/haydock-park/09-06-2016/fast-cards"
   
    Call openURL_IE1
   
    Set races = IEdoc1.getElementsByClassName("rac-dgp") ' all races info
    If races.Length > 0 Then
        copyRow = 1
        For i = 0 To races.Length - 1
            raceDescription = Trim(races(i).getElementsByClassName("hdr t2")(0).innerText)
            Set horseInfo = races(i).getElementsByClassName("ixt")
            If horseInfo.Length > 0 Then
                For ii = 0 To horseInfo.Length - 1
                    If InStr(horseInfo(ii).innerHTML, "racing/profiles/horse") > 0 Then
                        horseName = Trim(horseInfo(ii).getElementsByTagName("a")(0).innerText)
                        horseBF = ""
                        Set tempObject = horseInfo(ii).getElementsByClassName("sui enable-tooltip sui-bf")
                        If tempObject.Length > 0 Then
                            horseBF = "BF"
                        End If
                       
                        MyArray = Array(raceDescription, horseName, horseBF)
                        ws1.Range("A" & copyRow & ":C" & copyRow) = MyArray
                        copyRow = copyRow + 1
                    End If
                Next ii
            End If
        Next i
    End If
   
End Sub


I also tried the "horseInfo(ii).href" but isn't working
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm

Re: scrape sportinglife using Excel VBA

Postby youngstar » Thu Jun 09, 2016 9:39 pm

Great! That worked. :D

Thanks for the help, Al.

One thing I didn't mention when I said that I am able to get hold of the links for each race.
It's not using the fast cards. I get the links for each race like the 2 examples below, which means I can't plug these into your code.

http://www.sportinglife.com/racing/race ... icap-div-1
http://www.sportinglife.com/racing/race ... d-handicap

Do you have any codes that can get the links for each fastcard meeting, just like your previous code:-
"http://www.sportinglife.com/racing/meeting/haydock-park/09-06-2016/fast-cards"

I can then use your runners code to read in each meeting and display the runners and "BF".


Thanks
youngstar
 
Posts: 7
Joined: Fri Nov 15, 2013 2:07 pm

Re: scrape sportinglife using Excel VBA

Postby alrodopial » Thu Jun 09, 2016 10:38 pm

Code: Select all
Sub getFastCardLinks()
   
    Set ws1 = ThisWorkbook.Sheets("Sheet1")
    goURL = "http://www.sportinglife.com/racing/racecards"
   
    Call openURL_IE1
   
    Set fastCardLinks = IEdoc1.getElementsByClassName("sui-fastcards")
    If fastCardLinks.Length > 0 Then
        copyRow = 1
        For i = 0 To fastCardLinks.Length - 1
            ws1.Range("A" & copyRow) = fastCardLinks(i).href
            copyRow = copyRow + 1
        Next i
    End If
   
End Sub
alrodopial
 
Posts: 1353
Joined: Wed Dec 06, 2006 9:59 pm

Re: scrape sportinglife using Excel VBA

Postby youngstar » Sat Jun 11, 2016 9:43 pm

Al,
Excellent! Got it working. :D

Thanks for your help,
youngstar
 
Posts: 7
Joined: Fri Nov 15, 2013 2:07 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 46 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.