以下のコードではhandle、PDF をダウンロードしようとするたびに、この部分でエラーが発生しているようです。
url <- "http://brocktonpolice.com/wp-content/uploads/"
filename <- paste0(format(AllDays, '%Y/%m/%m%d%Y'), '.pdf')
filenames_list <- str_extract_all(filenames, 'uploads.+pdf')
downloadPDF <- function(filename, baseurl, folder, handle){
dir.create(folder, showWarnings = FALSE)
fileurl <- str_c(baseurl, filename)
if (!file.exists(str_c(folder,"/",filename))) {
content <- getBinaryURL(fileurl, curl = handle )
writeBin(content, str_c(folder,"/",filename))
Sys.sleep(1)
}
}
handle <- getCurlHandle(useragent = str_c(R.version$platform,
R.version.string, sep = ", "),
httpheader = c(from = "jomisilfe@gmail.com"))
l_ply(filenames_list, downloadPDF,
baseurl = "http://brocktonpolice.com/wp-content/uploads/",
folder = "Police_logs")
それらの PDF をダウンロードする方法についてのアイデアが尽きてしまいました。これが、すべてのPDFへのリンクを生成する方法です。
prefix <- "http://brocktonpolice.com/wp-content/uploads/"
AllDays <- seq.Date(from = as.Date('2015-01-01'), to = Sys.Date(), by = "day")
links <- paste0(prefix, format(AllDays, '%Y/%m/%m%d%Y'), '.pdf')
print(links)
ps: PDF をダウンロードする他の方法を考えられる場合は、コードを共有してください。
一部の URL ではエラーが発生する可能性があることに注意してください。日と月が 10 未満の場合、先頭にゼロがない場合があるためです。