gpt4 book ai didi

node.js - 如何在SpookyJS中注入(inject)脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 01:02:47 25 4
gpt4 key购买 nike

我正在尝试注入(inject)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

知道为什么它不起作用吗?

最佳答案

clientScripts 选项应该是 casper 哈希的一部分。

casper: {
logLevel: 'debug',
verbose: true,
clientScripts: ["punycode.js"]
}

关于node.js - 如何在SpookyJS中注入(inject)脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com