Last active
September 24, 2017 15:47
-
-
Save Ashley-Upson/062732b4707a6d6b2628ce380d62e81a to your computer and use it in GitHub Desktop.
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
scraper = { | |
lastRowShown: 0, | |
lastRowInSet: 0, | |
results: [], | |
complete: false, | |
prev: 1, | |
run: function() | |
{ | |
console.log("Initialising"); | |
var countInfo = $("#all_organizations_info").text(); | |
var countParts = countInfo.split(' '); | |
scraper.lastRowShown = parseInt(countParts[3].replace(',', '')); | |
scraper.lastRowInSet = parseInt(countParts[5].replace(',', '')); | |
console.log("Fetching data " + scraper.lastRowInSet); | |
setTimeout(scraper.scrape, 500); | |
}, | |
scrape: function() | |
{ | |
scraper.processGrid(); | |
var countInfo = $("#all_organizations_info").text(); | |
var countParts = countInfo.split(' '); | |
var lastrowOnPage = parseInt(countParts[3].replace(',', '')); | |
scraper.lastRowShown = lastrowOnPage; | |
if(scraper.lastRowShown == scraper.prev) | |
{ | |
console.log("Waiting for page update"); | |
setTimeout(scraper.scrape, 350); | |
} else { | |
$("#all_organizations_next a").click(); | |
console.log("Loading Next Page"); | |
scraper.prev = lastrowOnPage; | |
if(lastrowOnPage < scraper.lastRowInSet && scraper.complete == false) | |
{ | |
console.log(scraper.lastRowShown); | |
setTimeout(scraper.scrape, 350); | |
} else { | |
scraper.complete = true; | |
} | |
} | |
}, | |
processGrid: function() | |
{ | |
console.log("scraping " + $("#all_organizations_info").text()); | |
var grid = $("#all_organizations"); | |
var orgRows = $("tbody > tr[role=row]", grid); | |
for(var i = 0; i < orgRows.length; i++) { | |
scraper.parseRow($(orgRows[i])); | |
} | |
}, | |
parseRow: function(row) { | |
var cells = $("td", row); | |
var org = { | |
Image: $("img", cells[0]).attr("src"), | |
OrgName: $(cells[1]).text(), | |
OrgLink: "https://community.dualthegame.com" + $("a", $(cells[1])).attr("href"), | |
CreatedOn: $(cells[2]).text(), | |
MemberCount: $(cells[4]).text() | |
}; | |
console.log(org); | |
scraper.results.push(org); | |
} | |
}; | |
scraper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment