Created
September 12, 2017 00:49
-
-
Save vingkan/ca8da90e6e842327bd68b1392ac26c72 to your computer and use it in GitHub Desktop.
Scrape emails from HawkLink roster page.
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
var container = document.querySelector('[role="main"]').children[0].children[3].children[0].children[1].children[0]; | |
var boxes = Array.from(container.children); | |
var results = []; | |
getEmailByBoxIndex({ | |
container: container, | |
results: results, | |
boxes: boxes, | |
index: 0, | |
callback: printResults | |
}); | |
function printResults(results) { | |
results.forEach((res) => { | |
var out = res.name + ',' + res.email + '<br>'; | |
document.write(out); | |
}); | |
} | |
function getEmailByBoxIndex(params) { | |
var results = params.results; | |
var boxes = params.boxes; | |
var index = params.index; | |
var box = boxes[index]; | |
if (box) { | |
var subBox = box.children[0].children[0]; | |
subBox.click(); | |
querySelectorThen('[role="alert"]', function(alertBox) { | |
var nameBox = alertBox.children[0]; | |
var emailBox = alertBox.children[1]; | |
if (nameBox && emailBox) { | |
var name = nameBox.innerText.split('Name:')[1].trim(); | |
var email = emailBox.innerText.split('EmailAddress:')[1].trim(); | |
var res = { | |
name: name, | |
email: email | |
}; | |
results.push(res); | |
console.log(res); | |
} else { | |
console.log('Error: No profile found.'); | |
} | |
params.container.click(); | |
params.index++; | |
getEmailByBoxIndex(params); | |
}); | |
} else { | |
params.callback(results); | |
} | |
} | |
function querySelectorThen(queryString, callback) { | |
var interval = setInterval(function() { | |
var el = document.querySelector(queryString); | |
if (el) { | |
clearInterval(interval); | |
callback(el); | |
} | |
}, 250); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment