Last active
August 29, 2015 14:22
-
-
Save lsongdev/0e08d41e4c305f6523b6 to your computer and use it in GitHub Desktop.
unsplash images downloader
This file contains hidden or 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
| /** | |
| * | |
| * > 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