Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save lsongdev/0e08d41e4c305f6523b6 to your computer and use it in GitHub Desktop.

Select an option

Save lsongdev/0e08d41e4c305f6523b6 to your computer and use it in GitHub Desktop.
unsplash images downloader
/**
*
* > unsplash images downloader
*
* # Installtion
* ~$ npm install jsdom
*
* # Usage
* ~$ node unsplash.js
*/
var jsdom = require("jsdom");
//
;(function main(n, stop, arr, callback){
jsdom.env("https://unsplash.com/?page=" + n, [
"http://code.jquery.com/jquery.js"
], function(err, window){
if(err) return callback(err);
var $ = window.jQuery;
if(++n <= stop && ($("img").each(function(i, img){
var src = img.src.split('?')[0];
!~arr.indexOf(src) && arr.push(src); // && console.log(src);
}).size() > 0)){
main(n, stop, arr, callback);
}else{
callback(null, arr);
}
});
})(1, 1000 * 1000, [], function(err, images){
console.log(images);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment