Skip to content

Instantly share code, notes, and snippets.

@erberg-snippets
Last active August 29, 2015 13:57
Show Gist options
  • Save erberg-snippets/9376965 to your computer and use it in GitHub Desktop.
Save erberg-snippets/9376965 to your computer and use it in GitHub Desktop.
consoleScrape.js
/**
* Scrape indicated selectorString element from single or multiple web pages.
* @param {Number} numPages Number of pages to scrape. Depends on RESTful pagination.
* @param {String} urlRoot Base URL.
* @param {String} selectorString jQuery selector string.
* @param {Array} returnArray Array of jQuery objects matching the selectorString.
* @return {Array} returnArray
*/
function consoleScrape(numPages, urlRoot, selectorString, returnArray) {
if (!returnArray) {
var returnArray = [];
}
$.ajax({
url: urlRoot + numPagEs + '/',
success: function(data) {
$(data).find(selectorString).each(function(index, element) {
returnArray.push(element);
});
if (numPages > 1) {
consoleScrape(numPages - 1, urlRoot, selectorString, returnArray);
} else {
console.log(returnArray);
return returnArray;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment