3

我正在尝试开发一个使用 google Pagespeedinsights API 作为后端的应用程序。当我使用命令 curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=desired url为特定 url 运行 pagespeedinsights 时,我得到一个 json 数据作为响应。

   Sample JSON response
    {
     "captchaResult": "CAPTCHA_NOT_NEEDED",
     "kind": "pagespeedonline#result",
     "id": "https://jsonlint.com/",
     "loadingExperience": {
      "id": "https://jsonlint.com/",
      "metrics": {
       "FIRST_INPUT_DELAY_MS": {
        "percentile": 98,
        "distributions": [
         {
          "min": 0,
          "max": 50,
          "proportion": 0.9191070896432152
         },
         {
          "min": 50,
          "max": 250,
          "proportion": 0.05804188226370113
         },
         {
          "min": 250,
          "proportion": 0.022851028093083734
         }
        ],
        "category": "AVERAGE"
       },
       "FIRST_CONTENTFUL_PAINT_MS": {
        "percentile": 2784,
        "distributions": [
         {
          "min": 0,
          "max": 1000,
          "proportion": 0.5647038808001577
         },
         {
          "min": 1000,
          "max": 2500,
          "proportion": 0.3140323071688247
         },
         {
          "min": 2500,
          "proportion": 0.12126381203101773
         }
        ],
        "category": "SLOW"
       }
      },
      "overall_category": "SLOW",
      "initial_url": "https://jsonlint.com/"
     },
     "originLoadingExperience": {
      "id": "https://jsonlint.com",
      "metrics": {
       "FIRST_INPUT_DELAY_MS": {
        "percentile": 98,
        "distributions": [
         {
          "min": 0,
          "max": 50,
          "proportion": 0.9194600615254058
         },
         {
          "min": 50,
          "max": 250,
          "proportion": 0.05766680810438103
         },
         {
          "min": 250,
          "proportion": 0.022873130370213216
         }
        ],
        "category": "AVERAGE"
       },
       "FIRST_CONTENTFUL_PAINT_MS": {
        "percentile": 2774,
        "distributions": [
         {
          "min": 0,
          "max": 1000,
          "proportion": 0.5685563670116814
         },
         {
          "min": 1000,
          "max": 2500,
          "proportion": 0.3111175327063521
         },
         {
          "min": 2500,
          "proportion": 0.1203261002819664
         }
        ],
        "category": "SLOW"
       }
      },
      "overall_category": "SLOW",
      "initial_url": "https://jsonlint.com/"
     }

   I am doing it programatically.

String pythonScript = "import os\n" + "os.system(\"curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url= "+pageSpeedMetrics.getCompanyUrl()+" > "+PYTHON_FILE_LOCATION+文件名+"\")"; BufferedWriter out = new BufferedWriter(new FileWriter(PYTHON_FILE_LOCATION.concat(PAGESPEEDINSIGHT_PYTHON_FILE_NAME))); out.write(pythonScript); out.close(); System.out.println(pythonScript); 进程 p = r.exec("python "+PYTHON_FILE_LOCATION.concat(PAGESPEEDINSIGHT_PYTHON_FILE_NAME)+""); p.waitFor();

JSONObject json = new JSONObject(); json.put("crux_loading_experience", jsonPagespeedInsight.getJSONObject("loadingExperience")); json.put("crux_origin_loading_experience", jsonPagespeedInsight.getJSONObject("originLoadingExperience"));

但是当我使用https://developers.google.com/speed/pagespeed/insights/在线执行此操作时,我可以看到 FCP 和 FID 时间和百分比值,但在 json 文件中它不存在。它是如何产生的?提前致谢 !!!

4

0 回答 0