python - 有什么方法可以使用 Selenium Webdriver (firefox) 记录 http 请求/响应吗?

标签 python selenium webdriver

有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应?

我想可以通过代理驱动网络流量并记录它,但也许有更简单的“内部”selenium 解决方案?

在#selenium channel 上问了这个问题:

you will need to proxy it to capture the requests

所以,看起来这是为其设置代理的唯一方法。

最佳答案

现在是 2021 年,答案是:

您可以使用新库:selenium-wire

如何使用selenium-wire

安装

pip install selenium-wire

更改代码

改变自

from selenium import webdriver

from seleniumwire import webdriver

添加代码

driver.get(yourUrl) 之后,添加:

# Access requests via the `requests` attribute
for request in driver.requests:
    if request.response:
        print(
            request.url,
            request.response.status_code,
            request.response.headers['Content-Type']
        )

可以得到你期望的请求响应

关于python - 有什么方法可以使用 Selenium Webdriver (firefox) 记录 http 请求/响应吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12034013/

相关文章:

python - 选择元素不从 .first_selected_option() 方法返回 webelement

selenium - 在 Docker 容器中执行 Firefox 浏览器进行 Selenium 测试

java - 单击 Selenium 2.33 Java 中的隐藏菜单项

如果测试的应用程序在 80 以外的端口上运行,Selenium 会拒绝连接

javascript - Selenium-webdriver JS - 如何等到元素可见

python - 在 Selenium 中找不到项目时如何引发错误并转到其他功能

python - 在 python 2.4.3 中打开的替代方法是什么

python - 你能在python函数中有成员变量吗

python - AttributeError at/account/login/oauth/complete/facebook/'NoneType' 对象没有属性 'userprofile'

Python Selenium 访问多级 HTML