有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应? [英] Is there any way to log http requests/responses using Selenium Webdriver (firefox)?
问题描述
有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应?
我想可以通过代理驱动网络流量并记录它,但也许有更简单的内部"硒解决方案?
在#selenium 频道上问了这个问题:
<块引用><块引用><块引用>您需要代理它来捕获请求
所以,看起来是为它设置代理的唯一方法.
现在是 2021 年,答案是:YES.
您可以使用新库:selenium-wire
如何使用selenium-wire
安装
pip install selenium-wire
更改代码
更改自
from selenium import webdriver
到
from seleniumwire import webdriver
添加代码
在driver.get(yourUrl)
之后,添加:
# 通过 `requests` 属性访问请求对于 driver.requests 中的请求:如果请求响应:打印(请求.url,request.response.status_code,request.response.headers['Content-Type'])
可以得到你预期的request
和response
.
Is there any way to log http requests/responses using Selenium Webdriver (firefox)?
I guess it's possible to drive web traffic through proxy and log it, but maybe there is more simple "internal" selenium solution?
Asked this question on #selenium channel:
you will need to proxy it to capture the requests
so, looks like only way to setup proxy for it.
Now year 2021, answer is: YES.
you can use the new lib: selenium-wire
How to use selenium-wire
install
pip install selenium-wire
change code
change from
from selenium import webdriver
to
from seleniumwire import webdriver
add your code
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']
)
can got your expected request
and response
.
这篇关于有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!