1. #1
    Waterstpub87
    Slan go foill
    Waterstpub87's Avatar Become A Pro!
    Join Date: 09-09-09
    Posts: 4,043
    Betpoints: 7236

    Python Series : Draftkings MLB Batter Props

    For installation of python and selenium, please see this post

    https://www.sportsbookreview.com/for...-rotowire.html

    The background of this script was my changing from offshore to US books completely for this baseball season. Unfortunately, there is a large difference in the MLB props for offshore sites as compared to onshore sites. Typically, I had bet Hits/Runs/RBIs as a sum, which was the bets offered by the offshores. They offered it as a matchup, typically 2-4 matchups per games, and typically 4 single player over/unders. Similar with total bases. They had hits as well.

    Onshore, it seems to be that the offering is individual players. Needless to say, trying to manually price 18 * 4 props (18 players hits,runs,rbis,bases) is time consuming. I wrote this script to pull in the tables I wanted, and configured excel to read and price them.

    Draftkings prop page is set up into tables, IE 1 table for home run, 1 table for RBIs, ect.

    A note to remember is that python starts at 0 for numbering. So the first table (Home Runs, which would be 0) is ignored.

    This script will pull tables 2, 3, 4 ,5, which are Hits, Bases, RBI's and Runs.



    Below is example output:

    Player Category Line Over Odds Under Odds
    0 Abraham Toro Hits 0.5 -180 130
    0 Adam Frazier Hits 1.5 185 -250
    0 Alex Bregman Hits 0.5 -195 145
    0 Chas McCormick Hits 0.5 -165 120

    It will produce an excel sheet with this information.
    Points Awarded:

    peacebyinches gave Waterstpub87 250 Betpoint(s) for this post.

    Nomination(s):
    This post was nominated 2 times . To view the nominated thread please click here. People who nominated: peacebyinches, and mike1234

  2. #2
    Waterstpub87
    Slan go foill
    Waterstpub87's Avatar Become A Pro!
    Join Date: 09-09-09
    Posts: 4,043
    Betpoints: 7236

    Code:
    import pandas as pd
    
    from selenium import webdriver
    
    
    
    cols  = ['Player','Category','Line','Over Odds','Under Odds']
    
    props = pd.DataFrame(columns = cols)
    
    driver = webdriver.Chrome('Path to your chrome driver')
    
    driver.get('https://sportsbook.draftkings.com/event/180314630?category=odds&subcategory=batter-props')
    tables = driver.find_elements_by_xpath('//div[@class="sportsbook-event-accordion__wrapper expanded"]')
    
    for x in tables[1:5]:
        eventype = x.find_element_by_xpath('.//a[@aria-current="page"]').text
        rows = x.find_elements_by_xpath('.//tr')
        if eventype == 'Home Runs':
            betype = 'HR'
        elif eventype == 'Hits':
            betype = 'Hits'
            
        elif eventype == 'Total Bases':
            betype = 'TB'
            
        elif eventype == 'RBIs':
            betype = 'RBI'
        elif eventype == 'Runs Scored':
            betype = 'Runs'
        else:
            betype = 'Error'
        
        
        for z in rows[1:]:
            currentbet = pd.DataFrame(columns = cols)
            currentbet.at[0,"Player"] = z.find_element_by_xpath('.//span[@class="sportsbook-row-name"]').text
            currentbet.at[0,"Category"] = betype
            currentbet.at[0,"Line"] = z.find_element_by_xpath('.//span[@class="sportsbook-outcome-cell__line"]').text
            betodds = z.find_elements_by_xpath('.//span[@class="sportsbook-odds american default-color"]')
            
            currentbet.at[0,"Over Odds"] = betodds[0].text
            currentbet.at[0,"Under Odds"] = betodds[1].text
            props = props.append(currentbet)
            
    props.to_csv('MLBpropscrape.csv')    
    driver.close()

  3. #3
    Waterstpub87
    Slan go foill
    Waterstpub87's Avatar Become A Pro!
    Join Date: 09-09-09
    Posts: 4,043
    Betpoints: 7236

    To use this script, you must paste in the url of the game here:
    driver.get('https://sportsbook.draftkings.com/event/180314630?category=odds&subcategory=batter-props')

    you can go to the draft kings website to find this. Just click on a game on the main page, and you can find the event number.



    Additionally, I take only the 4 tables. If you wanted everything ( so what we have and HRs+Singles+Doubles+Triples + Stolen bases,

    go here :
    for x in tables[1:5]:

    and make it look like this :
    for x in tables:

    I rename some of them, which is the part that looks like this:


    elif eventype == 'Total Bases':
    betype = 'TB'

    if You are pulling in all the tables, the name will become "error" due to the coding. To fix this,

    take this part :
    betype = 'Error'

    and change it to:
    betype = eventype

    This script will output the table to where ever you have the script saved.

    If you want to save it somewhere else, specify it like this:

    directory = 'C\\Users\\Documents\\'
    It must be formated like that, double slashes within single quotes

    change this line:
    props.to_csv('MLBpropscrape.csv')
    to
    props.to_csv(directory + 'MLBpropscrape.csv')

  4. #4
    peacebyinches
    pull the trigger
    peacebyinches's Avatar SBR PRO
    Join Date: 02-13-10
    Posts: 1,108
    Betpoints: 7802

    This looks great! Something like this is the kind of tool for streamlining player props (which like you said, can get out of hand fast with the multiple stat categories across multiple players across multiple games) that I could definitely use. Thanks for sharing!

Top