Skip to content

Instantly share code, notes, and snippets.

@awavering
Created May 12, 2014 17:01
Show Gist options
  • Save awavering/28838586aceb40e926d4 to your computer and use it in GitHub Desktop.
Save awavering/28838586aceb40e926d4 to your computer and use it in GitHub Desktop.
BSD Team Page Scraper
var bsd=[];
$("article.headshot").each(function(){
var name = $("h4:first",this).text()
var email = $("a", this).text()+"bluestatedigital.com";
var city = $("h5:last", this).text();
var title = $("h5:first", this).text().replace(/\n/g," ");
var image = $("img", this).attr("src");
var team = null;
if(title.match(/Team/) || (title.match(/\,/) && !title.match(/(NY|DC|LA|UK|SF)$/) ) ) {
var split_title = title.split(", ");
var team = split_title.pop();
title = split_title.join(", ");
}
else{
team = "Management";
}
if(!team.match(/Team/)){
console.log(name, title, team);
}
title = title.replace(/ +/g,"").replace(/\n/g," ");
team = team.replace(/ +/g,"").replace(/\n/g," ");
var employee = {"name":name , "email": email, "city": city, "title": title, "image": image, "team": team };
bsd.push( employee );
});
var sql="INSERT INTO bsd.employees(name,email,city,title,image,team) VALUES";
for(var i=0;i<bsd.length;i++){var emp=bsd[i];
sql += '("' + emp.name + '","' + emp.email + '","' + emp.city + '","' + emp.title+ '","' + emp.image + '","' + emp.team + '"), ';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment