我是新手,刚学会使用覆盆子派和幻影。现在我正在使用phantomjs来测量网站的负载速度测试,所以我想知道如何使用bash脚本同时加载多个url(网站)。请帮帮我,我很感激,谢谢你。
这里是phantomjs给出的原始代码。
var page = require('webpage').create(),
system = require('system'),
t, address;
if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit(1);
} else {
t = Date.now();
address = system.args[1];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
t = Date.now() - t;
console.log('Page title is ' + page.evaluate(function () {
return document.title;
}));
console.log('Loading time ' + t + ' msec');
}
phantom.exit();
});
}发布于 2020-01-30 06:02:03
我想做与您尝试的完全相同的事情--我创建了一个副项目来测量实际的加载时间。它使用Node和Nightmare (以前在引擎盖下使用PhantomJS,但现在使用Electron)来操纵无头(“看不见”) web浏览器。加载完所有资源后,它会报告完全加载页面所用的毫秒数。
对你有用的一个很好的功能是它会重复加载网页。因此,您可以多次加载页面,然后对这些值进行平均,以获得一个很好的舍入值。此外,由于此脚本在命令行上运行,因此在不同的机器上安装并从不同的位置获取实际的加载时间是很容易的。(加载时间不仅取决于服务器,还取决于客户端和中介)
示例用法:
website-loading-time rinogo$ node website-loading-time.js https://google.com
1657
967
1179
1005
1084
1076
...https://github.com/rinogo/website-loading-time
披露:我是这个项目的作者。
https://stackoverflow.com/questions/47320879
复制相似问题