以下使用 casper.js
的代码不会输出 This is thenEvaluate
字符串,因为 Twitter.com 禁用了 console.log
(空函数):
var casper = require('casper').create({
verbose: false,
logLevel: 'debug'
});
casper.start("http://twitter.com");
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
})
casper.thenEvaluate(function() {
console.log('This is thenEvaluate');
});
casper.run();
如果我将网址交换为google.com或任何其他网站,它就可以工作。我的问题是:
对于禁用的网站
console.log
,有办法重新启用它吗?如果#1为“否”,有没有办法在
evaluate()
或thenEvaluate()
函数中执行任何类型的日志?
谢谢。
最佳答案
我在这里找到了关于Restoring console.log()的答案
var i = document.createElement('iframe');
i.style.display = 'none';
document.body.appendChild(i);
window.console = i.contentWindow.console;
关于javascript - 如果 console.log 禁用,则登录 casper.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13546970/