[英]How can I fetch info from the "Request Headers" of a specific request from the network tab using Python?
I'm trying to fetch a specific<\/strong><\/em> value of a specific<\/strong><\/em> request from the network tab using python.我正在尝试使用 python 从网络选项卡中获取特定<\/strong><\/em>请求的特定<\/strong><\/em>值。
For example, let's say I want to fetch the value stored in cookie<\/strong><\/em> from one of the get<\/strong><\/em> requests:例如,假设我想从其中一个get<\/strong><\/em>请求中获取存储在cookie<\/strong><\/em>中的值:
When I open the network tab<\/strong> I get these Fetch\/XHR requests, I select the get<\/strong><\/em> request: Image explanation<\/a>当我打开网络选项卡<\/strong>时,我收到这些 Fetch\/XHR 请求,我选择了获取<\/strong><\/em>请求:
图片说明<\/a>
After I click on the get<\/strong><\/em> request and I scroll down to the " Request Headers<\/em> " list I get the following values, I want to fetch the value of " cookie<\/strong><\/em> ": Image explanation<\/a>单击获取<\/strong><\/em>请求并向下滚动到“请求标头<\/em>”列表后,我得到以下值,我想获取“ cookie<\/strong><\/em> ”的值:
图片说明<\/a>
You can do this using seleniumwire:您可以使用 seleniumwire 执行此操作:
from seleniumwire import webdriver # Import from seleniumwire
# Create a new instance of the chrome web driver
driver = webdriver.Chrome()
url = "https://www.google.com/"
driver.get(url)
# Access requests via the `requests` attribute
for request in driver.requests:
if request.response:
# here you need to filter the name of the url request you want
# if "name_of_the_url_in_header" in request.url
print(
request.url
request.headers['cookie']
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.