Last active
August 29, 2015 14:02
-
-
Save jonaslund/8ce423f43417b0086e95 to your computer and use it in GitHub Desktop.
Download.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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