Javascript 如何检索浏览器web控制台日志并将其写入文件?
我正在尝试处理来自特定网页的日志。对于如何使用CasperJS从任何网页检索日志并将其放入文本文件,是否有任何建议?您可以使用事件从该网页接收所有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
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");
});
...