我正在尝试开发一个使用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 + fileName +” \“)”; BufferedWriter out =新的BufferedWriter(新的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 =新的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文件中却没有。它是如何产生的? 在此先感谢!!!