所以,我的問題可能非常愚蠢,但是有沒有辦法在發送之前檢查每個請求包含的標頭。我正在將 selenium 與 python 一起使用,但問題更多地轉向“這樣的事情是否可能”而不是“我如何將 selenium 與 python 一起使用”
重要我正在尋找的是一種無需發送請求即可做到這一點的方法。我知道您可以在發送后輕松地做到這一點,但是有沒有辦法在發送前檢查請求的標頭?
uj5u.com熱心網友回復:
您可以使用Selenium Wire,它是 Selenium 的擴展,添加了此功能。要在請求實際發送之前讀取標頭,您可以使用攔截器并在讀取/處理/列印標頭后中止請求
使用 pip ( pip install selenium-wire) 安裝后,您可以使用以下內容:
from seleniumwire import webdriver
def interceptor(request):
print(request.headers) # <--- Print the headers that would be sent
request.abort() # <---------- Abort the request so that it does not get sent.
driver = webdriver.Chrome()
driver.request_interceptor = interceptor
driver.get("https://my.test.url.com")
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/450455.html
標籤:Python 硒 硒网络驱动程序 网络驱动程序 浏览器自动化
