如何下载网站目录的一些图像

时间:2016-10-09 11:17:53

标签: javascript php html image

例如,我想从ID 663500下载图像到665000:

从这一个 http://geo.static.traxsource.com/files/images/663500_large.jpghttp://geo.static.traxsource.com/files/images/665000_large.jpg

我该怎么做?

2 个答案:

答案 0 :(得分:2)

我为你写了一个小脚本。这样每秒都会下载一个新文件。



var url = "http://geo.static.traxsource.com/files/images/{num}_large.jpg";
var startnum = 663500;
var endnum = 665000;
var interval = 1 * 1000; //in MS

function downloadNext(num) {
  if (num < endnum) {
    setTimeout(function() {
      downloadNext(num + 1);
    }, interval)
  }
  var downUrl = url.replace("{num}", num);
  aDownload(downUrl, num + "_large.jpg");
}

downloadNext(startnum);

//CREDITS TO: http://stackoverflow.com/questions/9900289/initiate-downloads-with-a-javascript-function
function aDownload(url, name) {
  // Original code from https://github.com/eligrey/FileSaver.js
  // Rewrited to work without blobs
  // Will return true if worked
  var click, save_link, event;
  save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
  if (!("download" in save_link)) return false; // a[download] not supported on this browser
  save_link.href = url;
  save_link.download = name;
  event = document.createEvent("MouseEvents");
  event.initMouseEvent(
    "click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
  );
  return save_link.dispatchEvent(event); // false if event was cancelled
}
&#13;
&#13;
&#13;

答案 1 :(得分:2)

// using JSZip to save a bunch of stuff
var zip = new JSZip
var from = 663500
var to = 663510
// requires cors headers...
var corsProxy = 'https://crossorigin.me/'
var src = corsProxy + 'http://geo.static.traxsource.com/files/images/'

// append a bunch of file we want to download
for (; from < to; from++) {
  let name = from + '_large.jpg'
  let url = src + name
  zip.file(name, fetch(url).then(res => res.blob()))
}

// generate the zip content
zip.generateAsync({
  type: 'blob'
})
// download using FileSaver.js
.then(blob => saveAs(blob, 'example.zip'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script>