I am trying to get the tables from this link: https://www.sports-reference.com/cfb/boxscores/2022-09-02-charlotte.html but it's not working for me.
I can scrape game detail, scores, and scoring summary but I cannot get the team_stats.
Any help is greatly appreciated.
Thanks
library(tidyverse)
library(rvest)
url <- "https://www.sports-reference.com/cfb/boxscores/2022-09-02-charlotte.html"
webpage <- read_html(url)
(team_names <- webpage %>%
html_nodes('div.scorebox strong a') %>%
html_text())
(scores <- webpage %>% html_nodes('div.score') %>% html_text())
(team_names <- setNames(team_names, c('away', 'home')))
(game_detail <- webpage %>%
html_nodes('#wrap') %>%
html_nodes('#content') %>%
html_node('h1') %>%
html_text()
)
(scores <- webpage %>%
html_nodes('#wrap') %>%
html_nodes('#content') %>%
html_nodes('.scorebox') %>%
html_nodes('div') %>%
html_nodes('.score') %>%
html_text2())
(scoring_summary <- webpage %>%
html_nodes('#wrap') %>%
html_nodes('#content') %>%
html_nodes('.table_container#div_scoring') %>%
html_table()
)
(team_stats <- webpage %>%
html_nodes('#wrap') %>%
html_nodes('#content') %>%
html_nodes(xpath = '//*[@id="div_team_stats"]') %>%
html_table()
)