如何检索浏览器 Web 控制台日志并将其写入文件?

How to retrieve browser web console log and write it into a file?

我正在尝试处理来自特定网页的日志。有没有关于如何使用 CasperJS 从任何网页检索日志并将其放入文本文件的建议?

//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);
}    

您可以使用 remote.message event to receive all console.log() from the page. Using that, you can write them into a file using PhantomJS' fs module (fs.write()).

var fs = require('fs');
casper.on("remote.message", function(msg){
    fs.write("file", msg+"\n", "a");
});
...