有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应?
我想可以通过代理驱动网络流量并记录它,但也许有更简单的“内部”硒解决方案?
在#selenium 频道上问了这个问题:
您将需要代理它来捕获请求
所以,看起来是为其设置代理的唯一方法。
现在是 2021 年,答案是:YES.
您可以使用新的库:硒线 https://github.com/wkeeling/selenium-wire
如何使用selenium-wire
install
pip install selenium-wire
更改代码
改变自
from selenium import webdriver
to
from seleniumwire import webdriver
添加您的代码
after driver.get(yourUrl)
, add:
# 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']
)
能达到你的预期request
and response
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)