[R] readHTMLTable() in XML package

Doran, Harold HDoran at air.org
Mon Mar 2 17:00:39 CET 2015


I'm having trouble pulling down data from a website with my code below as I keep encountering the same error, but the error occurs on different pages.

My code below loops through a wensite and grabs data from the html table. The error appears on different pages at different times and I'm not sure of the root cause.

Error in readHTMLTable(readLines(url), which = 1, header = TRUE) :
  error in evaluating the argument 'doc' in selecting a method for function 'readHTMLTable': Error in readHTMLTable(readLines(url), which = 1, header = TRUE) :
  error in evaluating the argument 'doc' in selecting a method for function 'readHTMLTable':

library(XML)
for(i in 1:1000){
                url <- paste(paste('http://games.crossfit.com/scores/leaderboard.php?stage=5&sort=0&page=', i, sep=''), '&division=1&region=0&numberperpage=100&competition=0&frontpage=0&expanded=1&year=15&full=1&showtoggles=0&hidedropdowns=0&showathleteac=1&=&is_mobile=0', sep='')
    tmp <- readHTMLTable(readLines(url), which=1, header=TRUE)
                names(tmp) <- gsub("\\n", "", names(tmp))
                names(tmp) <- gsub(" +", "", names(tmp))
    tmp[] <- lapply(tmp, function(x) gsub("\\n", "", x))

    if(i == 1){
                dat <- tmp
                } else {
                dat <- rbind(dat, tmp)
                }
                cat('Grabbing data from page', i, '\n')
                }

Thanks,
Harold

	[[alternative HTML version deleted]]



More information about the R-help mailing list