Skip to content

Instantly share code, notes, and snippets.

@kpq
Created June 24, 2013 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpq/5847028 to your computer and use it in GitHub Desktop.
Save kpq/5847028 to your computer and use it in GitHub Desktop.
Scrape every player ever in the NBA draft in R
library(XML)
years <- 1950:2012
data <- NULL
for (i in years) {
print(i)
url <- paste("http://www.basketball-reference.com/draft/NBA_", i, ".html", sep="")
page <- htmlTreeParse(readLines(url), useInternalNodes=T)
table <- readHTMLTable(page)$stats
table <- subset(table, Player!="Player" & College !="Totals")
table$year <- i
data <- rbind(data, table)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment