Skip to content

Instantly share code, notes, and snippets.

@fprieur
Created May 15, 2014 20:32
Show Gist options
  • Save fprieur/c662949a571ddd0986b7 to your computer and use it in GitHub Desktop.
Save fprieur/c662949a571ddd0986b7 to your computer and use it in GitHub Desktop.
working example with spookyjs
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../lib/spooky');
}
var spooky = new Spooky({
child: {
transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start(
'http://ville.montreal.qc.ca');
spooky.then(function () {
this.emit('hello', 'Hello, from ' + this.evaluate(function () {
return document.title;
}));
});
spooky.thenOpen("http://donnees.ville.montreal.qc.ca/");
spooky.then(function () {
this.emit('bonjour', 'bonjour ' + this.evaluate(function () {
return document.title;
}));
});
spooky.then(function () {
this.capture('monsieur.png');
});
spooky.run();
});
spooky.on('error', function (e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
/*
// Uncomment this block to see all of the things Casper has to say.
// There are a lot.
// He has opinions.
spooky.on('console', function (line) {
console.log(line);
});
*/
spooky.on('hello', function (greeting) {
console.log(greeting);
});
spooky.on('bonjour', function(bonjourmonsieur) {
console.log(bonjourmonsieur);
});
spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment