phantomjs学习之网页访问测速
1.编写loadpage2.js文件:
loadpage2.js
1 var page = require('webpage').create(), 2 system = require('system'), 3 t, address; 4 if(system.args.length == 1){ 5 console.log('Usage: loadpage.js <some URL>'); 6 phantom.exit() 7 } 8 t = Date.now(); 9 address = system.args[1]; 10 page.open(address, function (status) { 11 if (status !== 'success') { 12 console.log('Unable to load the address!'); 13 14 } else { 15 t = Date.now() - t; 16 console.log('Loading '+ system.args[1]); 17 console.log('Loading time ' + t + ' msec'); 18 } 19 phantom.exit(); 20 });
2.运行测试: