1 min read

Scraping Odds

Table 1: NBA Champ Odds
Team PointsBet DraftKings
Celtics -303 +1100
Nuggets -303 +2000
Lakers -303 -333
Heat -303 +375

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 a few 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 _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")