有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应? [英] Is there any way to log http requests/responses using Selenium Webdriver (firefox)?

查看:48
本文介绍了有没有办法使用 Selenium Webdriver (firefox) 记录 http 请求/响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 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'])

可以得到你预期的requestresponse.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆