-
-
Save thomaswilburn/79222074f4928777c64be3243f2d0c87 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
var request = require("request"), | |
fs = require("fs"), | |
cheerio = require("cheerio"), | |
json2csv = require("json2csv"), | |
url = "https://www.wilkescc.edu/about-us/directory/?letter="; | |
var alpha = "abcdefghijklmnopqrstuvwxyz".toUpperCase().split(""); | |
var all_emails = [], | |
first_names = [], | |
last_names = [], | |
counter = 0; | |
var everything = { | |
content: [] | |
}; | |
// don't use for...in for arrays, it may behave unpredictably | |
alpha.forEach(function(letter) { | |
request(url + letter.toLowerCase(), function(error, res, body){ | |
if (error) return console.log(error); | |
counter++; | |
var $ = cheerio.load(body); | |
// find people | |
var containers = $('.w3-container.w3-twothird'); | |
var people = containers.toArray().map(function(element) { | |
var $element = $(element); | |
var name = $element.text().match(/Name: (.*)/)[1].trim(); | |
var email = $element.find(`[href^="mailto:"]`).attr("href").replace(/mailto:/, ""); | |
return { name, email }; | |
}); | |
console.log(people); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment