Last active
August 29, 2015 14:18
-
-
Save bmeck/20a85685ee2d852cc6ef to your computer and use it in GitHub Desktop.
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
| function scrape(url) { | |
| var page = ''; //or whatever | |
| var fulfill,reject; | |
| var ret = new Promise(function (f,r) { | |
| fulfill = f; | |
| reject = r; | |
| }); | |
| function getPage(current) { | |
| request(current, function (err, data) { | |
| if (err) { | |
| reject(err); | |
| } | |
| //logic to see if this is the last page | |
| else if (last_page) { | |
| fulfill(aggregate); | |
| } | |
| else { | |
| page += data; | |
| // logic to find the next page | |
| getPage(next_page); | |
| } | |
| }) | |
| } | |
| getPage(url); | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment