Skip to content

Instantly share code, notes, and snippets.

@strongh
Created August 8, 2016 17:10
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 strongh/b3ab0d2a00ff25f03b653b7bc46b0c11 to your computer and use it in GitHub Desktop.
Save strongh/b3ab0d2a00ff25f03b653b7bc46b0c11 to your computer and use it in GitHub Desktop.
nrs <- rep(seq(1,5,1),2)
sex <- c("M","M","M","M","M","F","F","F","F","F")
links <- NULL
#Loop to create 10 links, 5 for the male age grou 18-24, 5 for women agegroup 18-24. However,
#there are only 3 pages in the male age group with a table.
for (i in 1:length(nrs) ) {
links[i] = paste("http://www.ironman.com/triathlon/events/americas/ironman/texas/results.aspx?p=",nrs[i],"&race=texas&rd=20160514&sex=",sex[i],"&agegroup=18-24&loc=",sep="")
}
resultlist <- list() #create empty list to store results
for (i in 1:length(links)) {
tryCatch({
results = readHTMLTable(links[i],
as.data.frame = TRUE,
which=1,
stringsAsFactors = FALSE,
header = TRUE) #get data
resultlist[[i]] <- results #combine results in one big list
}, error = function(e){
print(paste("Failed for ", links[i]))
})
}
results = do.call(rbind, resultlist) #combine results into dataframe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment