0

I'm trying to scrape a table from a player page on Sports Reference's college basketball site using rvest. I'm a total novice at scraping so I haven't had much success. The URL I'm trying to scrape from is https://www.sports-reference.com/cbb/players/anthony-davis-5.html and the tables I'd like to scrape are the "Advanced" and "Per 100 Poss" tables. I saw another answer suggested something like this:

ad <- 'https://www.sports-reference.com/cbb/players/anthony-davis-5.html'

advanced_df <-  ad %>%
  read_html %>%
  html_nodes(xpath = '//comment()') %>%
  html_text() %>%
  paste(collapse='') %>%
  read_html() %>% 
  html_node("#advanced") %>% 
  html_table()

when using basketball reference but this hasn't worked for me on college basketball reference. Any help would be much appreciated.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
Matt
  • 41
  • 4
  • Maybe this question https://stackoverflow.com/questions/73791745/webscraping-with-rvest-https-www-sports-reference-com. There are 2 different approaches for answers. – Dave2e Jun 18 '23 at 04:45
  • 1
    Those particular tables don't seem to originate from comments; you shouln't need much more than `read_html('https://www.sports-reference.com/cbb/players/anthony-davis-5.html') %>% html_elements("table#players_advanced, table#players_per_poss") %>% html_table()` – margusl Jun 19 '23 at 13:29

0 Answers0