Hi everyone, I'm having some issues with my code and was wondering if anyone had any ideas on how to fix it?
Currently, what I have done is to scrape multiple direct URL image links into a data frame and subsequently using R to download the images to a temporary folder.
What I would like to achieve is for R to go through every row in my data frame and download the respective image.
However, for some reason R seems to stop at a certain number which I would like to fix
Here's the dataframe of URLs I have created:
library("rvest")
library("ralger")
male <- vector("list", num_pages)
# saving the urls from istockphoto
for(page_result in 1:num_pages){
link = paste0("https://www.istockphoto.com/search/2/image?alloweduse=availableforalluses&mediatype=photography&phrase=man&page=",
page_result)
male[[page_result]] <- images_preview(link)
}
male <- unlist(male)
male <- as.data.frame(male) # make it a data frame
# adding IDs to dataset
data <- tibble::rowid_to_column(male, "ID")
summary(data)
# drop first row
test <- data[-1,]
Here's the code I used to download the images:
# downloading loop
for (i in 1:304) {
myurl <- paste(test[i,2], sep = "")
a <- tempfile()
download.file(myurl,a,mode="wb")
pic <- readJPEG(a)
writeJPEG(pic, paste("image", "i", ".jpg", sep = ""))
file.remove(a)
}