Created
September 24, 2012 15:28
-
-
Save pcomans/3776525 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
"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