1
我正在嘗試處理來自特定網頁的日誌。是否有任何建議如何使用CasperJS從任何網頁檢索日誌並放入文本文件?如何檢索瀏覽器Web控制檯日誌並將其寫入文件?
我正在嘗試處理來自特定網頁的日誌。是否有任何建議如何使用CasperJS從任何網頁檢索日誌並放入文本文件?如何檢索瀏覽器Web控制檯日誌並將其寫入文件?
可以使用remote.message
事件從頁面接收所有console.log()
。使用它,您可以使用PhantomJS的fs模塊(fs.write()
)將它們寫入文件。
var fs = require('fs');
casper.on("remote.message", function(msg){
fs.write("file", msg+"\n", "a");
});
...
//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_那麼你可以_shadow_'console.log'等 –