OZmium Sports Betting and Horse Racing Forums

OZmium Sports Betting and Horse Racing Forums (http://forums.ozmium.com.au/index.php)
-   General Topics (http://forums.ozmium.com.au/forumdisplay.php?f=59)
-   -   Help on XML feed (http://forums.ozmium.com.au/showthread.php?t=28398)

evajb001 21st May 2014 04:12 PM

Here's the code to get more then 1 race on the same sheet, should help you figure out how to get all races in a basic sense. Obviously you can build on this so that it works out how many races for that venue etc etc but this should give you a good starting block to get it all working.

Sub LoadRaceField()

Dim xmldoc As MSXML2.DOMDocument

Set xmldoc = New MSXML2.DOMDocument

xmldoc.async = False
xmldoc.Load ("http://tatts.com/pagedata/racing/2014/5/21/SR1.xml")

If (xmldoc.parseError.errorCode <> 0) Then
MsgBox ("An error has occurred: " & xmldoc.parseError.reason)
Else
Set runnerList = xmldoc.selectNodes("//Runner")
Set oddsList = xmldoc.selectNodes("//WinOdds")

Sheet1.Cells.Clear

For i = 0 To (runnerList.Length - 1)

Set Runner = runnerList.Item(i)
Set winodds = oddsList.Item(i)

Set runnerNumber = Runner.Attributes.getNamedItem("RunnerNo")
Set runnerName = Runner.Attributes.getNamedItem("RunnerName")
Set runnerWeight = Runner.Attributes.getNamedItem("Weight")
Set riderName = Runner.Attributes.getNamedItem("Rider")
Set runnerOdds = winodds.Attributes.getNamedItem("Odds")


If Not runnerNumber Is Nothing Then
Sheet1.Cells(i + 1, 1) = runnerNumber.Text
End If

If Not runnerName Is Nothing Then
Sheet1.Cells(i + 1, 2) = runnerName.Text
End If

If Not runnerWeight Is Nothing Then
Sheet1.Cells(i + 1, 3) = runnerWeight.Text
End If

If Not riderName Is Nothing Then
Sheet1.Cells(i + 1, 4) = riderName.Text
End If

If Not runnerOdds Is Nothing Then
Sheet1.Cells(i + 1, 5) = runnerOdds.Text
End If

Next
End If

Race2
End Sub

Sub Race2()

Dim xmldoc As MSXML2.DOMDocument

Set xmldoc = New MSXML2.DOMDocument

xmldoc.async = False
xmldoc.Load ("http://tatts.com/pagedata/racing/2014/5/21/SR2.xml")

If (xmldoc.parseError.errorCode <> 0) Then
MsgBox ("An error has occurred: " & xmldoc.parseError.reason)
Else
Set runnerList = xmldoc.selectNodes("//Runner")
Set oddsList = xmldoc.selectNodes("//WinOdds")

For i = 0 To (runnerList.Length - 1)

Set Runner = runnerList.Item(i)
Set winodds = oddsList.Item(i)

Set runnerNumber = Runner.Attributes.getNamedItem("RunnerNo")
Set runnerName = Runner.Attributes.getNamedItem("RunnerName")
Set runnerWeight = Runner.Attributes.getNamedItem("Weight")
Set riderName = Runner.Attributes.getNamedItem("Rider")
Set runnerOdds = winodds.Attributes.getNamedItem("Odds")


If Not runnerNumber Is Nothing Then
Sheet1.Cells(i + 25, 1) = runnerNumber.Text
End If

If Not runnerName Is Nothing Then
Sheet1.Cells(i + 25, 2) = runnerName.Text
End If

If Not runnerWeight Is Nothing Then
Sheet1.Cells(i + 25, 3) = runnerWeight.Text
End If

If Not riderName Is Nothing Then
Sheet1.Cells(i + 25, 4) = riderName.Text
End If

If Not runnerOdds Is Nothing Then
Sheet1.Cells(i + 25, 5) = runnerOdds.Text
End If

Next
End If

End Sub

EDIT: I noticed it seems to load quicker then doing the web queries too, might have to be something I look at using instead.

Shaun 21st May 2014 04:31 PM

Nake sure you add the "s" to the address https://tatts.com/pagedata/racing/2014/5/21/SR7.xml

Rinconpaul 21st May 2014 04:33 PM

You're destined for higher things Josh, I've always said that! Not only are you brilliant but you're willing to help others when asked. If you ever need a character reference, just ask.

Now from what I can work out, I'll need to amend the script (is that what you call it?) for each raceday date, venue and race number?

Is the result that I see on the page a continually updating one or is it static, as in a picture of the tote odds at the instant I executed the button?

I wanted this so as to load a scatter chart instantly and start cataloging 'star patterns' ???,.......... you know, for the upcoming book! Which by the way, you'll be getting the first signed copy of...:)

Cheers again.

evajb001 21st May 2014 04:39 PM

RCP, it will be like taking a screenshot of whatever is viewable on the website at the time you press the button.

In terms of changing the date, venue and race number that is something you'll have to do within the script (macro) at the moment, however it should be possible to make it so you can put these details into cells within the spreadsheet, hit the button and it will update without actually having to go within the script and risk disrupting anything.

Let me see what I can come up with and i'll post a bit later. In theory it shouldn't be too difficult but computers find a way of never making things that easy.

Rinconpaul 21st May 2014 04:45 PM

1 Attachment(s)
I'll look forward to that improvement. I seem to remember about a year ago you doing something similar?

Anyway here's the first print run below, brilliant.

Rinconpaul 21st May 2014 05:29 PM

I just checked out which horse won SR2, the bottom image on the prev post's jpg. It was that 'faraway star' the longshot Speedy Wally BF $65, the highest priced horse in the race.

As a longshot Layer, I never got caught by that one, in fact no accidents in over 3 weeks, and I have to thank the systems I've built around the Ratings 2 Win data, which had it 'in the Green' for a possibility of an upset win. That just saved me $2k in one bet, the cost of purchasing the Pro package and 3 months subscription. Onya R2W. Still a way to go, to adapt the system for the Layers though....:)

Does this mean an end to 'star gazing', not likely, there's still money to be made.

Shaun 21st May 2014 05:29 PM

I hard codded a couple cells for the date and the race code

on sheet1 in cell I1 put =Today()
In cell K1 put your race code like SR1

Had to also adjust the clear function so it only clears to row E

Sub LoadRaceField()

Dim xmldoc As MSXML2.DOMDocument

Set xmldoc = New MSXML2.DOMDocument

xmldoc.async = False
xmldoc.Load ("https://tatts.com/pagedata/racing/" & Format(Sheets("Sheet1").Range("I1").Value, "yyyy/m/dd") _
& "/" & Sheets("Sheet1").Range("K1").Value & ".xml")

If (xmldoc.parseError.ErrorCode <> 0) Then
MsgBox ("An error has occurred: " & xmldoc.parseError.reason)
Else
Set runnerList = xmldoc.SelectNodes("//Runner")
Set oddsList = xmldoc.SelectNodes("//WinOdds")

Sheets("sheet1").Range("A1:E50").Select
Selection.ClearContents
Range("A1").Select

For i = 0 To (runnerList.Length - 1)

Set Runner = runnerList.Item(i)
Set winodds = oddsList.Item(i)

Set runnerNumber = Runner.Attributes.getNamedItem("RunnerNo")
Set runnerName = Runner.Attributes.getNamedItem("RunnerName")
Set runnerWeight = Runner.Attributes.getNamedItem("Weight")
Set riderName = Runner.Attributes.getNamedItem("Rider")
Set runnerOdds = winodds.Attributes.getNamedItem("Odds")


If Not runnerNumber Is Nothing Then
Sheet1.Cells(i + 1, 1) = runnerNumber.Text
End If

If Not runnerName Is Nothing Then
Sheet1.Cells(i + 1, 2) = runnerName.Text
End If

If Not runnerWeight Is Nothing Then
Sheet1.Cells(i + 1, 3) = runnerWeight.Text
End If

If Not riderName Is Nothing Then
Sheet1.Cells(i + 1, 4) = riderName.Text
End If

If Not runnerOdds Is Nothing Then
Sheet1.Cells(i + 1, 5) = runnerOdds.Text
End If

Next
End If

End Sub

Shaun 21st May 2014 05:35 PM

What you could also do is set up a sheet to bring in the meetings first then you could setup a list to choose the races or if data collection is needed it could be designed to run in auto mode.

Rinconpaul 21st May 2014 05:50 PM

Thanks for your input Shaun. I'd like to see the perfect setup posted here for all forumites to access. There's been quite a few posts on the subject in the past, coz I searched. They were all ad hoc, with no final solution revealed. Not as if your giving the 'Grail' away here. More power to all forumites, I say! Heaven knows, we need it.

evajb001 21st May 2014 06:01 PM

1 Attachment(s)
Here you go RCP, give this a try as attached


All times are GMT +10. The time now is 12:43 PM.

Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.