Skip to content

Instantly share code, notes, and snippets.

@jonaslund
Last active August 29, 2015 14:02
Show Gist options
  • Save jonaslund/8ce423f43417b0086e95 to your computer and use it in GitHub Desktop.
Save jonaslund/8ce423f43417b0086e95 to your computer and use it in GitHub Desktop.
Download.js
var jsdom = require("jsdom");
var http = require('http-get');
jsdom.env(
"http://jonaslund.biz",
["http://code.jquery.com/jquery.js"],
function (errors, window) {
var images = window.$("img");
for (var i = images.length - 1; i >= 0; i--) {
var src = console.log(images[i]._attributes.src);
}
}
);
function downloadFromSrc(uri, filename, callback) {
var options = {url: uri};
http.get(options, filename, function (error, result) {
if (error) {
console.error(error);
callback('ERROR' + filename);
} else {
callback('File downloaded at: ' + filename);
}
});
}
downloadFromSrc("http://jonaslund.biz/wp-content/uploads/2014/05/splash.jpg", "test.jpg", function() {
console.log("SUCCESS");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment