Last active
August 29, 2015 13:57
-
-
Save erberg-snippets/9376965 to your computer and use it in GitHub Desktop.
consoleScrape.js
This file contains 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
/** | |
* 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