Slide 17
Slide 17 text
• PhantomJS 收集数据方法:
var page = require(‘webpage’).create(), fs = require('fs'), content = '';
page.onLoadStarted = function () {
page.onResourceRequested = function (request) {
content +='Request ' + JSON.stringify(request, undefined, 2));
};
page.onResourceReceived = function (response) {
content +='Receive ' + JSON.stringify(response, undefined, 2));
};
}
page.onLoadFinished = function () {
fs.write('c:\\a.txt', content, 'w')
};
page.open('http://www.taobao.com');
// 还有下载时间没计算呢,写丌下丌写了……
// 额,好像 DNS 、Waitting 时间啥的没法计算 = =|||
// phantomJS 的例子文件 netsniff.js 里 DNS 啥的时间写的都是 -1 ……
// 丌过写了 130 行里有一半是为了拼 HAR 格式数据