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文件中导出。我也试过进入绝对路径。