如何获得Lighthouse API的有效响应

2024-05-19 18:19:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想得到google lighthouse API的一个结果,如果我在浏览器中键入它,这个结果就会起作用 https://developers.google.com/speed/pagespeed/insights/?hl=de

如果将API与get-request一起使用,则会显示某些域的错误

通过此请求,在我的浏览器中或使用我的python代码:

import requests


mobile_performance = requests.get('https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://de.wikipedia.org/wiki/Test%2F&fields=lighthouseResult%2Fcategories%2F*%2Fscore&prettyPrint=false&strategy=desktop&category=performance&category=pwa&category=best-practices&category=accessibility&category=seo&key=**')
result_mobile = mobile_performance.json()
print(result_mobile)

我得到以下错误:

{'error': {'code': 500, 'message': 'Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Status code: 404)', 'errors': [{'message': 'Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Status code: 404)', 'domain': 'lighthouse', 'reason': 'lighthouseError'}]}}

有没有办法得到一个实际的结果,因为在谷歌的网站上它是有效的。 我想添加一些headers,但我想它不会起作用,因为如果我在浏览器中键入它,它会抛出相同的错误

编辑:仍未解决


Tags: thetohttpsyouperformance错误google浏览器