I tested this on a small subset (3) of 56 files per page, and it works great.
url <- "http://www2.census.gov/geo/docs/maps-data/data/rel/t00t10/"
zips <- XML::getHTMLLinks(
url,
xpQuery = "//a/@href['.zip'=substring(., string-length(.) - 3)]"
)
dir.create("myzips")
wd <- getwd()
setwd("myzips")
file.create(zips)
lapply(paste0(url, zips), function(x) download.file(x, basename(x)))
## reset working directory to original
setwd(wd)
Now all zip files are in the directory myzipsand ready for further processing. Alternatively, lapply()you can also use a loop for().
for(u in paste0(url, zips)) download.file(u, basename(u))
And, of course, the installation quiet = TRUEcan be enjoyable, as we upload 56 files.
source
share