我正在尝试从某些页面中获取Google的Pagespeed Index Lighthouse得分,但我似乎无法弄清楚为什么我会得到这些数字。
我能够正确地从Pagespeed API的版本4中获得分数,而不能从版本5中获得分数。我发现有一些人炫耀如何使用以前的版本进行评分,但是我对V5的灯塔结果最感兴趣。
这是来自pagespeed API的JSON数据: https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.digitaltrends.com/movies/best-shows-on-netflix/&strategy=desktop
这是非JSON数据(我想要总体得分): https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fwww.digitaltrends.com%2Fmovies%2Fbest-shows-on-netflix%2F
function pageSpeedInsights(url) {
url = url || 'https://www.digitaltrends.com/movies/best-shows-on-netflix/'; //
//Logger.log(http_secure); // for test runs. Comment it out if you like. See logs using Ctrl + Enter.
//Logger.log(http_protocol); // for test runs. Comment it out if you like.
var key = 'AIzaSyB74YShnSZL1Vt0QlC59Qpw5w1gHA-S9rY'; // Get the API key from Google Dev Console
var api = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=' + url
+ '&strategy=desktop' + '&key=' + key;
https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.digitaltrends.com/movies/best-shows-on-netflix/&strategy=desktop
//Logger.log(api); // for test runs. Comment it out if you like.
//Logger.log(url); // for test runs. Comment it out if you like.
var response = UrlFetchApp.fetch(api, {muteHttpExceptions: true });
var result = JSON.parse(response.getContentText());
test = result.lighthouseResult.categories.performance.score;
//Logger.log(test); // for test runs. Comment it out if you like.
//return(test);
}
我希望在台式机上获得0.80的得分,但继续保持0.37或0.50的得分。