Skip to content

Instantly share code, notes, and snippets.

@pcomans
Created September 24, 2012 15:28
Show Gist options
  • Save pcomans/3776525 to your computer and use it in GitHub Desktop.
Save pcomans/3776525 to your computer and use it in GitHub Desktop.
"use strict";
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
casper.echo('Casper started...');
casper.start('http://designit.com/team');
function Employee() {
}
function getTextContent(node) {
//get stringified text content if node exists
return node ? JSON.stringify(node.textContent.trim()) : "";
}
function getEmployees() {
var links = document.getElementsByClassName('employee-teaser');
var linkArray = Array.prototype.slice.call(links);
var employees = linkArray.map(function (value) {
info = value.getElementsByClassName('info-wrapper')[0];
currentEmployee = new Employee();
currentEmployee.name = getTextContent(info.querySelector('[itemprop="name"]'));
currentEmployee.jobTitle = getTextContent(info.querySelector('[itemprop="jobTitle"]'));
currentEmployee.education = getTextContent(info.querySelector('.education'));
currentEmployee.worksFor = getTextContent(info.querySelector('[itemprop="worksFor"]'));
currentEmployee.telephone = getTextContent(info.querySelector('[itemprop="telephone"]'));
currentEmployee.mobile = getTextContent(info.querySelector('[itemprop="mobile"]'));
currentEmployee.email = getTextContent(info.querySelector('[itemprop="email"]'));
return currentEmployee;
});
return employees;
}
casper.then(function () {
var e = this.evaluate(getEmployees);
this.echo(e);
});
casper.on('remote.message', function(msg) {
this.echo('R: ' + msg);
});
casper.run(function () {
this.echo('Finished!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment