I'm trying to scrape HTML tables from different football teams. Here is the table I want to scrape, however I want to scrape that same table from all of the teams to ultimately create a single CSV file that has the player names and their data.
http://www.pro-football-reference.com/teams/tam/2016_draft.htm
# teams
teams <- c("ATL", "TAM", "NOR", "CAR", "GNB", "DET", "MIN", "CHI", "SEA", "CRD", "RAM", "NWE", "MIA", "BUF", "NYJ", "KAN", "RAI", "DEN", "SDG", "PIT", "RAV", "SFO", "CIN", "CLE", "HTX", "OTI", "CLT", "JAX", "DAL", "NYG", "WAS", "PHI")
# loop
for(i in teams) {
url <-paste0("http://www.pro-football-reference.com/teams/", i,"/2016-snap-counts.htm#snap_counts::none", sep="")
webpage <- read_html(url)
# grab table
sb_table <- html_nodes(webpage, 'table')
html_table(sb_table)
head(sb_table)
# bind to dataframe
df <- rbind(df, sb_table)
}
I'm getting an error thought that I should use CSS or Xpath and not both, but I can't figure out where the problem is exactly (I suspect the html_nodes command). Can anyone help me fix this problem?
df
from? - Cyrus Mohammadianteams
not be lower-case? - neilfwsdf<-data.frame()
outside your loop or you will overwrite it on each iteration. - Dave2e