首页 > 解决方案 > 以自动方式获得整体灯塔分数

问题描述

我正在尝试自动获取许多不同页面的分数。但是 api 似乎并没有像网页版那样提供总分。

我试过使用 Lighthouse API v5 和 v4,似乎都没有得分,我可能错过了。我通过在 pagespeed 洞察网站上使用 puppeteer 让它工作,但它已经停止工作,并且想检查我没有错过任何东西,然后再尝试再次修复它

标签: pagespeedgoogle-pagespeedlighthousepagespeed-insights

解决方案


返回的 JSON 在lighthouseResult名为的部分下有一个部分categories

categories会看到performance里面score有一个孩子,得分为 1 分(所以 89 的分数是 0.89)。

"lighthouseResult": {
......
    "categories": {
        "performance": {
            "id": "performance",
            "title": "Performance",
            "score": 1.00, <- here is the score.
            "auditRefs":
......

推荐阅读