我想获取我网站的特定 JavaScript 和 CSS 网络请求的状态 https://lifesciences.cactusglobal.com 。这些网络请求可以在chrome网络中看到。我想打印请求 URL 及其响应代码。下面附上截图供引用,请检查划线的请求:
我尝试使用包 selenium-wire
driver.get('https://www.google.com')
for request in driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
)
但它仅返回输入 URL 的响应和 header ,而不返回网络请求。有没有其他方法可以在selenium python中遍历网络请求?
谢谢
最佳答案
输出一团糟,但是尝试像这样获取网络请求,它似乎对我有用:
driver.get('https://lifesciences.cactusglobal.com/')
time.sleep(3)
test = driver.execute_script("var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;")
for item in test:
print(item)
关于python - 如何在selenium python中从网络获取javascript和css请求的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67613901/