今天我尝试使用CasperJS和PhantomJS一起向远程页面注入一些javascript逻辑.
嗯,我很惊讶因为:
casper.then(function() {
console.log(this.evaluate(function() {
function myMethod() {
return 'Any thing?!';
}
return myMethod();
}));
console.log(this.evaluate(function() {
return myMethod();
}));
});
Run Code Online (Sandbox Code Playgroud)
我试过很多组合...喜欢:
casper.evaluate(...)
this.evaluate(...)
casper.page.evaluate(...) <- directly to phantomJS
this.page.evaluate(...) <- as above
Run Code Online (Sandbox Code Playgroud)
第一个案例给了我我想要的东西.但接下来要求评估作为一个白痴,从未见过上面执行过的代码.
我只想更改变量,函数和其他远程站点js运行时.
任何人都可以告诉我为什么会这样吗?问候.