2 min read

Scraping Odds

Table 1: NBA Champ Odds
Team PointsBet BetMGM Bet365
Celtics +1600 +1800 +1500
Nets +20000 +20000 +15000
Mavericks +4000 +3000 +4000
Nuggets +2500 +2200 +2200
Rockets +1200 +1200 +1400
Pacers +8000 +10000 +12500
Clippers +300 +325 +333
Lakers +250 +250 +229
Grizzlies +15000 +50000 +15000
Heat +3000 +2500 +3000
Bucks +250 +280 +229
Pelicans +12500 +12500 +10000
Thunder +10000 +8000 +7000
Magic +25000 +25000 +15000
76ers +2000 +2500 +2000
Suns +100000 +100000 +15000
Blazers +12500 +8000 +8000
Kings +25000 +50000 +25000
Spurs +50000 +50000 +15000
Raptors +2000 +2200 +1400
Jazz +4000 +2500 +2500
Wizards +100000 +50000 +30000

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 of three sports books.

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 odds-cell')]") %>% 
  rvest::html_text()

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

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


chart_df <- data.frame(team, pb, mgm, bet365)

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