PhantomJS はネットワーク監視を提供しているようです。
例 ( netlog.js ):
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: netlog.js <some URL>');
phantom.exit(1);
} else {
address = system.args[1];
page.onResourceRequested = function (req) {
console.log('requested: ' + JSON.stringify(req, undefined, 4));
};
page.onResourceReceived = function (res) {
console.log('received: ' + JSON.stringify(res, undefined, 4));
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
phantom.exit();
});
}
phantomjs をインストールし、パスに配置します。上記のコードを「netlog.js」として保存し、コマンドラインから netlog.js を含むフォルダーに移動して、コマンドを実行しますphantomjs netlog.js "http://www.example.com"
。