2015-05-07 46 views

回答

0

可以使用remote.message事件從頁面接收所有console.log()。使用它,您可以使用PhantomJS的fs模塊(fs.write())將它們寫入文件。

var fs = require('fs'); 
casper.on("remote.message", function(msg){ 
    fs.write("file", msg+"\n", "a"); 
}); 
... 
0
//Keep a reference to the original function 
var original = console.log; 

//Override the function 
console.log = function(arg) { 

    //Do what you want with the arguments of the function 
    .... 

    //Call the original function 
    original.call(this, arguments); 
}  
相關問題