1
내 SpookyJS 프로그램에 punycode 스크립트를 주입하려고합니다. 하지만 작동하지 않습니다.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,
options: {
clientScripts: ["punycode.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 = punycode.encode("hi");
console.log("x: "+x);
});
});
spooky.run();
});
spooky.on('error', function (e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
spooky.on('console', function (line) {
console.log(line);
});
spooky.on('remote.message', function(message) {
console.log('[Inside Evaluate] ' + message);
});
콘솔 출력에 x 값이 표시되지 않습니다.
$ node test.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: http://www.google.com/, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.google.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=http://www.google.co.kr/?gfe_rd=cr&ei=y1EKVPjzK6eL8Qfl4oDoBA, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://www.google.co.kr/?gfe_rd=cr&ei=y1EKVPjzK6eL8Qfl4oDoBA"
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] start page is loaded
[info] [phantom] Step anonymous 3/3 http://www.google.co.kr/?gfe_rd=cr&ei=y1EKVPjzK6eL8Qfl4oDoBA (HTTP 200)
[Inside Evaluate] testing
[info] [phantom] Step anonymous 3/3: done in 1293ms.
[info] [phantom] Done 3 steps in 1311ms
왜 작동하지 않는가?
@ArtjomB. 콘솔 출력에 x 값이 표시되지 않습니다. – vinayr