try {
var Spooky = require("spooky");
} catch (e) {
console.log(e);
}
var spooky = new Spooky({
capser: {
logLevel: "debug",
verbose: true
},
child: {
command: "./casperjs/bin/casperjs",
port: 8081,
spooky_lib: "./node_modules/spooky/"
}
}, function (err) {
if(err) {
console.log(err);
}
spooky.start("http://www.google.com");
spooky.then(function () {
console.log("7331");
this.emit("printmsg", "1337");
});
spooky.run();
});
spooky.on("printmsg", function (msg) {
console.log(msg);
});
spooky.on("error", function (e) {
console.error(e);
});
When run, 1337
will be displayed, but 7331
will not. Why is this? The reason I'm asking is because it makes it difficult to debug when you want to log the values of certain variables.
Also, if you want to change the then function like so:
spooky.then(function () {
var self = this;
this.evaluate(function () {
self.emit("printmsg", "Hello World!");
});
});
This won't work because evaluate
doesn't have access to the self variable. In PhantomJS you can make it page.evaluate(function (self) {
but that isn't working when I try it with Spooky. So it's very difficult to log data when you want to.
Is there a way around this?