try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../lib/spooky');
}
var spooky = new Spooky({
child: {
transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true,
clientScripts: ["abc.js"]
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start("http://www.google.com");
spooky.then(function(){
this.evaluate(function() {
console.log("testing");
var x = abc.check();
console.log("x: "+x);
});
});
spooky.run();
});
spooky.on('console', function (line) {
console.log(line);
});
spooky.on('remote.message', function(message) {
console.log('[Inside Evaluate] ' + message);
);
私の出力は次のとおりです。
[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: https://www.google.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.google.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://www.google.co.in/?gfe_rd=cr&ei=ZIXqVvXoGuHI8AeX06uYAg, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.google.co.in/?gfe_rd=cr&ei=ZIXqVvXoGuHI8AeX06uYAg"
[debug] [phantom] Automatically injected /Users/BitBucket/headless_browser/abc.js client side
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] start page is loaded
[info] [phantom] Step anonymous 3/3 https://www.google.co.in/?gfe_rd=cr&ei=ZIXqVvXoGuHI8AeX06uYAg (HTTP 200)
end of
[info] [phantom] Step anonymous 3/3: done in 1037ms.
remote message caught: testing
[info] [phantom] Done 3 steps in 1055ms
x の値がわかりません。関数の前に「testing」というテキストのみが表示されます。casper オプションのみにファイルを挿入し、関数は js ファイルにエクスポートされます。絶対パスも入力してみました。