8

I need some help with this script that I'm trying to make that downloads all of the images on a webpage. It downloads the first image just fine, then when Google Chrome tries to download the rest of them, it says "No File". Some help would be greatly appreciated. I run this code by pasting it into the javascript console. Thanks!

var images = document.getElementsByTagName('img');
var srcList = [];
var i = 0;

setInterval(function(){
    if(images.length > i){
        srcList.push(images[i].src);
        var link = document.createElement("a");
        link.id=i;
        link.download = srcList;
        link.href = srcList;
        link.click();
        i++;
    }
},1500);
nern9
  • 83
  • 1
  • 1
  • 3

3 Answers3

13

You’re using an entire array as the src attribute. try:

var images = document.getElementsByTagName('img');
var srcList = [];
var i = 0;

setInterval(function(){
    if(images.length > i){
        srcList.push(images[i].src);
        var link = document.createElement("a");
        link.id=i;
        link.download = images[i].src;
        link.href = images[i].src;
        link.click();
        i++;
    }
},1500);
Radio
  • 2,810
  • 1
  • 21
  • 43
3

Try this simpliest solution:

var images = document.getElementsByTagName('img');
var i = 0;

setInterval(function(){
    if(images.length > i){
        window.open(images[i].src,'_blank');
        i++;
    }
},1000);

If you still have problem with downloading, you can try with iframe. or harder solution with mod_headers method.

Community
  • 1
  • 1
Garrett
  • 367
  • 1
  • 14
0

let webphotos = document.images;
Array.from(webphotos).forEach((extractedimages) => {
  console.log(extractedimages);
});

first of all this code extracts all the images form the website as u can see further u can do any custom operation on them according to your needs