1 min read

Scraping Odds

Table 1: NBA Champ Odds
Team Best365
Lakers +333
Clippers +450
Bucks +600
Warriors +550
Nets +900
Heat +1600
Celtics +1300
Raptors +1800
Nuggets +2200
Mavericks +2500
Rockets +2200
76ers +2000
Jazz +3300
Blazers +4500
Pelicans +5000
Thunder +8000
Pacers +10000
Suns +10000
Hawks +10000
Bulls +25000
Grizzlies +12500
Timberwolves +15000
Magic +12500
Wizards +15000
Kings +15000
Spurs +10000
Hornets +20000
Cavaliers +25000
Pistons +20000
Knicks +25000

Web scraping sounds hard. I’m finding it’s not too difficult with tools like rvest.

This is a simple example pulling together markdown table of team’s odds to make the NBA Championship. It pulls from OddsBoom and selects the odds from a sportsbook(s).

There isn’t any sorting, converting of the odds, and styling done.

Code is below . . .

library(knitr)
library(rvest)

odds <- read_html('https://www.oddsboom.com/nba/futures/22-nba-championship/')

team <- odds %>% 
  rvest::html_nodes('table') %>% 
  xml2::xml_find_all("//td[contains(@class, 'competitor')]") %>% 
  rvest::html_text()

pb <- odds %>% 
  rvest::html_nodes('table') %>% 
  xml2::xml_find_all("//td[contains(@class, 'goto pb _pb odds-cell null  odds-above-average ')]") %>% 
  rvest::html_text()

dk <- odds %>% 
  rvest::html_nodes('table') %>% 
  xml2::xml_find_all("//td[contains(@class, 'goto dk _dk odds-cell null')]") %>% 
  rvest::html_text()


chart_df <- data.frame(team, pb, dk)

kable(chart_df, col.names = c("Team",
                           "PointsBet",
                           "DraftKings"
                           ), caption = "NBA Champ Odds", format="markdown")