Skip to content

Instantly share code, notes, and snippets.

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

  • Save bmeck/20a85685ee2d852cc6ef to your computer and use it in GitHub Desktop.

Select an option

Save bmeck/20a85685ee2d852cc6ef to your computer and use it in GitHub Desktop.
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