python - 如何在selenium python中从网络获取javascript和css请求的状态

标签 python selenium-webdriver http-headers

我想获取我网站的特定 JavaScript 和 CSS 网络请求的状态 https://lifesciences.cactusglobal.com 。这些网络请求可以在chrome网络中看到。我想打印请求 URL 及其响应代码。下面附上截图供引用,请检查划线的请求:

enter image description here

我尝试使用包 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/

相关文章:

html - XPath//*[text()]没有选择我想要的文本

java - 在星期几文本字段中输入值

java - 如何使用仅带有 SRC 的 Selenium 单击图像

使用 rel ="next"rel ="prev"HTTP header 的分页 SEO

python - 从 Django 中具有多对多关系的查询集列表中删除对象

python - 如何添加一个列表,从子进程传递到父进程,到python中已经存在的列表

python - 如何优雅地检查字典是否具有给定的结构?

python - 如何使用Scrapy采集页面不同部分的数据?

使用 xargs 后 curl header

http - 如何根据 HTTP 请求获取响应 header ?