python - 如何在 Selenium 中获取请求 header

标签 python selenium fiddler

https://www.sahibinden.com/en

如果您打开它的隐身窗口并在 Fiddler 中检查标题,那么这些是您获得的两个主要标题:
enter image description here

当我单击最后一个并检查请求 header 时,这就是我得到的
enter image description here

我想在 Python 中获取这些 header 。有什么办法可以使用 Selenium 获得这些吗?我在这里有点不知所措。

最佳答案

您可以使用 Selenium 线。它是为此目的而开发的 Selenium 扩展。
https://pypi.org/project/selenium-wire/
pip 安装后的示例:

##  Import webdriver from Selenium Wire instead of Selenium
from seleniumwire import webdriver

##  Get the URL
driver = webdriver.Chrome("my/path/to/driver", options=options)
driver.get("https://my.test.url.com")

##  Print request headers
for request in driver.requests:
  print(request.url) # <--------------- Request url
  print(request.headers) # <----------- Request headers
  print(request.response.headers) # <-- Response headers

关于python - 如何在 Selenium 中获取请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62262261/

相关文章:

python - 先按字母排序包含字母数字项目的列表

python - 简单的 GUI Windows 拖放

java - 使用 Selenium Java 无法到达元素的 xPath

python - 为什么我无法使用 Selenium 打开 google.com?

proxy - 我可以使用 fiddler 模拟掉线连接吗?

windows-phone-7 - 如何在通过 USB 电缆连接时监控 WP7 HTTP 流量

python - 如何获取子类(class)的名称?

python - pyad:安装正常,但说找不到 adbase

python - 什么可能导致此 Python 代码有时失败?

jQuery ajax 调用,服务器响应很晚?