Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何检索浏览器web控制台日志并将其写入文件?_Javascript_Automation_Casperjs - Fatal编程技术网

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

Javascript 如何检索浏览器web控制台日志并将其写入文件?,javascript,automation,casperjs,Javascript,Automation,Casperjs,我正在尝试处理来自特定网页的日志。对于如何使用CasperJS从任何网页检索日志并将其放入文本文件,是否有任何建议?您可以使用事件从该网页接收所有console.log()。使用它,您可以使用PhantomJS的fs module()将它们写入一个文件 //Keep a reference to the original function var original = console.log; //Override the function console.log = function(arg

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

您可以使用事件从该网页接收所有
console.log()
。使用它,您可以使用PhantomJS的fs module()将它们写入一个文件

//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);
}    
如果他们正在登录控制台,那么您可以对
Console.log
等进行阴影处理
var fs = require('fs');
casper.on("remote.message", function(msg){
    fs.write("file", msg+"\n", "a");
});
...