casperjs的evaluate函数中使用casper.log就无法输出,代码如下
var casper = require('casper').create({
'verbose': true,
'logLevel': 'debug'
});
casper.start('http://www.baidu.com/', function() {
this.evaluate(function() {
this.log('asd', 'error'); // 这一条无法输出
});
});
大概的原因我也知道,应该是evaluate中的东西相当于在一个sandbox中执行,要与外界交互是只能通过特定的接口的
但这样造成我写程序的不便,因为在evaluate函数中就可能发生一些不可预期的情况,而我想把它log下来
我目前有两种解决方案
第二种解决方法的代码
casper.start('http://www.baidu.com/', function() {
this.evaluate(function() {
console.log('asd');
});
});
casper.on('remote.message', function(msg) {
this.log(msg, 'info');
});
所以有什么更好的解决方案吗?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
光阴似箭催人老,日月如移越少年。