Go Back   Sports Handicapping Forum > Welcome Forums > Main Street > Capping

Capping All handicapping, betting systems, spreadsheets, mathematics & quantitative technicapping.

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-27-2010, 04:06 PM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Grabbing Pinnacle Lines with Excel and DOM

DOM (Document Object Model) is one of the many HTML/XML to programming language routines that use a common toolbox for which to call its properties. Fortunately for us, Visual Basic, Java, PHP, etc… all integrate these toolbox routines in order to grab and manipulate information given a particular XML/HTML source. For a general information scraper, its one of the more expansive and user-friendly, though with simplicity comes limitations. However, such limitations pose very little concern for extracting basic information from a website. DOM doesn’t necessarily promote dynamic streaming information parsing, because DOM typically requires the document source to be loaded in complete form into memory. If you think of DOM as a branching tree, with each element a branch, or “child”, or its root, or “parent”, then its obvious why the information must be in some way stored in memory before the various DOM elements can be called.

DOM can be more useful in extracting box scores or season statistics. Such data is in a complete state and does not require any other web and programming integration to grab information that is changing, as opposed to line movement or live game updates.

Below is the code for extracting NCAA lines and matchups via Pinnacle’s XML feed using Excel. Excel’s VBA Modules allows these DOM properties to be implemented, after referencing the relevant toolbox routines. So before accessing the DOM methods, create a reference to Microsoft XML, v6.0



Pinnacle’s full XML feed is located at:

Code:
http://xml.pinnaclesports.com/pinnacleFeed.aspx?
and they are kind enough to offer some assistance on how to get different lines from the different sports offered.



The URL parameters are given above, so to access solely the lines for NCAA football, use the following parameters:

Code:
http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=NCAA
XML files are configured, as mentioned before, as subsequent branches from a tree, whose root is the document source. The DOM properties to access each branch are in a rather English familial vernacular, to make it human-friendly. For example, the following XML sequence:
Code:
 <game>
<date>10/23</date>
<hometeam>USC</hometeam>
<roadeam>Oregon</roadteam>
</game>
Contains the “game” element, or node, as the parent to its three children, or child node, “date”, “hometeam”, and “roadteam”. The latter three are designated as siblings.

Each element in the document is numbered sequentially from an initial value of zero. Therefore to grab just the home team from above, its DOM properties translate to the second child node, childnode(1), of the parent node “game”.

The VB code is honestly rather self explanatory from there. Some trial and error and a google search or two is needed in order to find the right properties and naming conventions to fit the programming language. Excel is user-friendly enough to provide all the properties available for the particular function required.

Code:
Sub XML_Pinny()
    Dim xmlLoad As New MSXML2.DOMDocument
    Dim allevents As IXMLDOMNode
    Dim eventslen As Integer
    Dim events As IXMLDOMNode
    Dim XMLHttpRequest As MSXML2.xmlhttp
    Dim i As Integer
    Dim URL As String
 
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error Resume Next
 
    URL = "http://xml.pinnaclesports.com/pinnaclefeed.aspx?sporttype=Football&sportsubtype=NCAA"

    Set XMLHttpRequest = New MSXML2.xmlhttp
    XMLHttpRequest.Open "GET", URL, False
    XMLHttpRequest.send
    Set xmlLoad = New MSXML2.DOMDocument

    Do Until xmlLoad.readyState = 4
    Loop
    xmlLoad.LoadXML (XMLHttpRequest.responseText)
 
    Sheets("Sheet1").Range("A1").Value = xmlLoad.DocumentElement.ChildNodes(0).FirstChild.Text
 
    Set allevents = xmlLoad.DocumentElement.ChildNodes(3)
 
    eventslen = allevents.ChildNodes.Length
    Sheets("Sheet1").Range("B1").Value = eventslen
 
    i = 0
    For i = 0 To (eventslen - 1) Step 1
        Set events = allevents.ChildNodes(i)
        Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp)(2, 1) = events.FirstChild.Text
        Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp)(2, 1) = events.ChildNodes(5).ChildNodes(0).FirstChild.Text
        Sheets("Sheet1").Cells(Rows.Count, 4).End(xlUp)(2, 1) = events.ChildNodes(5).ChildNodes(1).FirstChild.Text
        Sheets("Sheet1").Cells(Rows.Count, 3).End(xlUp)(2, 1) = events.LastChild.FirstChild.SelectSingleNode("spread").FirstChild.Text &amp; " " &amp; events.LastChild.FirstChild.SelectSingleNode("spread").ChildNodes(1).Text
        Sheets("Sheet1").Cells(Rows.Count, 5).End(xlUp)(2, 1) = events.LastChild.FirstChild.SelectSingleNode("spread").ChildNodes(2).Text &amp; " " &amp; events.LastChild.FirstChild.SelectSingleNode("spread").ChildNodes(3).Text
    Next i
 
Set xmlLoad = Nothing
Set allevents = Nothing
 
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
 
'Application.OnTime Now + TimeValue("00:02:00"), "XML_Pinny"
End Sub

The lines:
Code:
 

Do Until xmlLoad.readyState = 4
    Loop
Simply means do not continue until the document is completely loaded into memory (readyState = 4).

Remove the comment from the final line to run the program every two minutes.

The final result should look something like this:

__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000

Last edited by uva3021; 10-27-2010 at 04:17 PM.
Reply With Quote
  #2  
Old 10-28-2010, 12:18 AM
the straightshooter
 
Join Date: Aug 2004
Location: an onrushing tram, on collision course
Posts: 46,820
Rewards: 855
<tup>
__________________
The only bridge I've ever burned along this legacy I dance is the one that linked the cities of prosperity and chance

Check out Technicapping for quantitative sport analysis
Reply With Quote
  #3  
Old 04-14-2011, 10:59 PM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Been getting a lot of PMs over at sbr about this, bumperoo for relevance

Post here if you want the MLB version, though with the provided instructions you should be able to do it yourself
__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000
Reply With Quote
  #4  
Old 04-17-2011, 12:56 PM
Registered User
 
Join Date: May 2010
Posts: 2
Rewards: 55
Follow up on Offer for MLB

I will take you up on your offer, for the MLB version.

Thank you in advance

Pancho
Reply With Quote
  #5  
Old 04-18-2011, 06:49 PM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Unzip the file, enable macros, Click the "GET" button
Attached Files
File Type: zip MLB_Pinnacle.zip (26.1 KB, 58 views)
__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000
Reply With Quote
  #6  
Old 04-19-2011, 12:03 PM
Registered User
 
Join Date: May 2010
Posts: 2
Rewards: 55
Smile Thx UV

Thank you UV, works great
Reply With Quote
  #7  
Old 04-19-2011, 02:33 PM
Registered User
 
Join Date: May 2010
Posts: 3
Rewards: 55
When I click the button it says the macro can't run. Ideas?
Reply With Quote
  #8  
Old 04-19-2011, 07:37 PM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Quote:
Originally Posted by carl5793 View Post
When I click the button it says the macro can't run. Ideas?
What exactly does the error message say? It may be a security issue, check your security options and make sure macros are enabled.
__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000
Reply With Quote
  #9  
Old 04-20-2011, 10:42 AM
Registered User
 
Join Date: May 2010
Posts: 3
Rewards: 55
I checked the security, it should be fine. "Cannot run the macro 'MLB_Pinnacle.xlsm!Button_3Click'." The macro may not be available in this workbook or all macros may be disabled (which they aren't).
But when I go to Macros and run XML_Pinny it works
Reply With Quote
  #10  
Old 04-20-2011, 10:52 AM
Registered User
 
Join Date: May 2010
Posts: 3
Rewards: 55
Nevermind figured it out. Thanks!
Reply With Quote
  #11  
Old 05-02-2011, 07:11 AM
Football Fan
 
Join Date: Apr 2011
Location: China
Posts: 52
Rewards: 60
I'll take you up on your offer, for the MLB version.
Thanks foe advice
Reply With Quote
  #12  
Old 05-02-2011, 05:25 PM
Registered User
 
Join Date: Apr 2011
Posts: 1
Rewards: 25
Quote:
Originally Posted by uva3021 View Post
Been getting a lot of PMs over at sbr about this, bumperoo for relevance

Post here if you want the MLB version, though with the provided instructions you should be able to do it yourself
Any recommendations that are Mac friendly? Excel for Mac 2011 (with vba support) but no MS XML availability.
Reply With Quote
  #13  
Old 05-03-2011, 02:36 AM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Quote:
Originally Posted by except View Post
Any recommendations that are Mac friendly? Excel for Mac 2011 (with vba support) but no MS XML availability.
i'll work on one for javascript
__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000
Reply With Quote
  #14  
Old 06-07-2011, 01:38 AM
Registered User
 
Join Date: Jun 2011
Posts: 2
Rewards: 30
Quote:
Originally Posted by uva3021 View Post
i'll work on one for javascript
hi, uva did you look into a mac friendly version? thanks
Reply With Quote
  #15  
Old 06-09-2011, 12:52 AM
Hall of Fame
 
Join Date: Oct 2005
Location: Salem, VA
Posts: 22,450
Rewards: 1,800
Quote:
Originally Posted by ichigoFAN1 View Post
hi, uva did you look into a mac friendly version? thanks
here is a php version to screen scrape MLB odds, it outputs in a plain html style page with comma delimited fields

in order to run you need to have server space, or just download xampp and run a virtual server from your computer

if you want to have server space, signing up for a quick blogspot page might actually be worth the trouble just to have the ability to run local php files

PHP Code:
<?php

$raw 
file_get_contents("http://www.pinnaclesports.com/League/Baseball/MLB/1/Lines.aspx");

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");

$content str_replace($newlines""html_entity_decode($raw));

$start strpos($content,'<table class="linesTbl" cellspacing="1" border="0">');

$end strpos($content,'</table>',$start);

$table substr($content,$start,$end-$start);

preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
//$handle = fopen('pinnybaseballtxt.txt', 'w');
//echo "<table>";
foreach ($rows[0] as $row){

    if ((
strpos($row,'<h4')===false)&&(strpos($row,'colspan')===false)){
   
        
preg_match_all("|<td(.*)</td>|U",$row,$cells);
       
        
$date strip_tags($cells[0][0]);
       
        
$rot strip_tags($cells[0][1]);
       
        
$team strip_tags($cells[0][2],"<BR /><EM>");
        
$teamandname str_replace("<EM>"", "$team);
        
        
$rl strip_tags($cells[0][4]);
        
        
$ml strip_tags($cells[0][5]);
        
        
$total strip_tags($cells[0][6]);
        
$tline substr($total, -4);
        
$tnumber substr($total0, -5);
        
        echo 
"{$date}, {$rot}, {$teamandname}, {$rl}, {$ml}, {$total} <br>\n";
        
//echo "<tr><td>{$date}</td><td>{$rot}</td><td>{$teamandname}</td><td>{$rl}</td><td>{$ml}</td><td>{$tnumber}</td><td>{$tline}</td></tr> <br>\n";
        //$pinnylines = "{$date}, {$rot}, {$teamandname}, {$rl}, {$ml}, {$total} <br>\n";
        //fwrite($handle, $pinnylines);
        //fclose ($handle);
        
    
}
}
?>
__________________
"Nobody goes there anymore, its too crowded." --Yogi Berra

"Always tell the truth, that way you won't have to remember what you said." --Mark Twain


*=$50,000
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:47 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.