Skip to content

Instantly share code, notes, and snippets.

@thomaswilburn
Forked from lindsaycarbonell/wilkes.js
Last active February 2, 2018 17:57
Show Gist options
  • Save thomaswilburn/79222074f4928777c64be3243f2d0c87 to your computer and use it in GitHub Desktop.
Save thomaswilburn/79222074f4928777c64be3243f2d0c87 to your computer and use it in GitHub Desktop.
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