0

I am trying to save images from a list of URLS and assign names per another list like was explained here.

URL

list_examples <- c( "https://www.bluemoonfiberarts.com/newmoon/index.php?main_page=index&amp;cPath=19_20_1632&amp;zenid=7c3hdt095727v28lsbn6nrj184", 
"https://www.bluemoonfiberarts.com/newmoon/index.php?main_page=index&amp;cPath=19_20_1894&amp;zenid=7c3hdt095727v28lsbn6nrj184", 
"https://www.bluemoonfiberarts.com/newmoon/index.php?main_page=index&amp;cPath=19_20_1644&amp;zenid=7c3hdt095727v28lsbn6nrj184")

Designated names

names_examples = c('A Total Eclipse of the Sun', 
'Autumn Moon Glow', 
'Bewitched')

Iterate through the file and download each file with corresponding name:

for (i in 1:length(list_examples )){
    download.file(list_examples [i], destfile =  names_examples [i], mode = 'wb')
}

I tried editing the mode to jpg and that didn't work and there's no function for download.jpg

thank you

tangerine7199
  • 443
  • 2
  • 8
  • 24
  • It is just hitting the url and. not the image file i.e. you may have to inspect the website and get the url of image `https://www.bluemoonfiberarts.com/newmoon/images/home/BMFA_SockClub2019_HomeGraphic.jpg` – akrun Sep 09 '21 at 00:05
  • are you sure you are trying to download images ? the url's refers to web page. – Samet Sökel Sep 09 '21 at 00:05
  • that's a good point. thank you. can we save the url as a png? – tangerine7199 Sep 09 '21 at 00:08

1 Answers1

0

If we inspect the website can get the url of the image from the src (Below is the example that shows the first link and its downloaded output)

list_example1 <- "https://www.bluemoonfiberarts.com/newmoon/images/home/BMFA_SockClub2019_HomeGraphic.jpg"
download.file(list_example1, destfile = names_examples[1], mode = "wb")

-checking the output

enter image description here enter image description here


If we want to save as .png, paste the suffix into the 'names_examples'

download.file(list_example1, destfile = paste0(names_examples[1], 
      ".png"), mode = "wb")
akrun
  • 874,273
  • 37
  • 540
  • 662