How to get a specific value from a html header

2024/11/16 6:46:13

Im using selenium to get request headers from a web page, the problem is that it prints out all request headers sent and i want to get only one value from one of them. I dont know how to do it and i havent found anything on the internet, I used this line of code to get the request headers ```

from seleniumwire import webdriver
for req in driver.requests:print(req.headers)

and this is ex. what the console prints out

/Users/andrew/Downloads/andrewtate/respon.py:8: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() insteadelement = driver.find_element_by_id("liveSwitch")
content-length: 537
x-ms-apiversion: 2
uaid: 4276e35e10994d41a4f8b9d772597415
sec-ch-ua-mobile: ?0
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36
canary: ZsWLDeZFgz9FMStm3ag92konX3u1nFMb5JrOsAmAVOXif1MhviASbSrIbTSEBeVN3swoIqb9Nxrhv29kmwRlAreLZxaTbyMXlhcBjeXQL/xXtNVRAHzRRn841XYbOsaAnTtD+m/+0eseb0AOal3OUUrXRuCNiMQTfWV94E4rG3wbhVc+wOFKr6CJdRbdnHCJJ+KKCCyD6Zi5iiyYy/WDeOpiRm4bGTJfxovswmLBI+vSh8+8gmclbitKCSQ9WNCi:2:3c
content-type: application/json
hpgid: 200639
accept: application/json
tcxt: IC/zaA2dVnLbOoFiW8OysFIi9WGFKCMw3gul+hWJLmefmKsjmQrWIqWZCo8QxPdDls8y71f/SzThuntkwVS/j97OYNFlvyZ1i9dX/9gOt+vc5YF7DPd9K2UETiLyWfr8q4UfLF7XZejtifraNmhTXKKnWHlY9wzl3qs6lMPuHxrwkRCHSqA/vhyzar0B0YV2uaC3EJJLBn7X2UYtNegmlvZsMyBBkOwEaRad0Yv+J2X2hsdKUxLu+c6pnKVgRYQetqDlFy9ZWjSFekw898Q7dWwziwXGv+CnlMvFOMq4kRz+O9KtpNpLP7ASxmBYiJHsI9TPtyLOae4aYyhFkg5trpzbobT2dS+r/uiz4hmySwHA44gRVz7JCVM9+xnxA+Q2UuizMPniv+4pz4KdNpuxO3ib2ptN0IsBJ0syUMbBriC3/UcdAs9YcueQlojUhnFOb+WEBRzEfbY2Dn3l4RhuaUXdCsNNaNGY78vtQ0X6XlduYnrwtVAf9sGDraiT3aQ7+g/2BJohKnfnH69WjkaWVf/OUQ0fVpZJDzglZIaf7sJOCOEPNm3mqgBJ/S+K0awK:2:3
uiflvr: 1001
scid: 100118
sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"
x-ms-apitransport: xhr
sec-ch-ua-platform: "macOS"
origin: https://signup.live.com
sec-fetch-site: same-origin
sec-fetch-mode: cors
sec-fetch-dest: empty
referer: https://signup.live.com/signup?lic=1&uaid=4276e35e10994d41a4f8b9d772597415
accept-encoding: gzip, deflate, br
accept-language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7
cookie: amsc=b55INNzzHR5PZiPunWJJsx3fMAbVhvWRQlJkJfRh2zNI+jGPtSvnOYjXiJqnEctddyQyWNV64rFgnX9Qf57EA+YiA/VCFcqp6ogo+iXCvLBLpDne1H1QImvS5lgln9YT1eI5JbSQYm789c/XXcVi3mCEE9vKzuLq4CovhNTdvcBk/hXxtcDePtoNIZOjrfUSfP4/Gp34hMJFNK79iAo2rhl/WK9jO894h00DrAKnMEiA4Cd57LVili0DAOXInzcFSQ7TjRXBpNr2KoO2RB1ARd9sjjaQfycR/n6r6P5Fj+o=:2:3csec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
sec-fetch-site: same-site
sec-fetch-mode: navigate
sec-fetch-dest: iframe
referer: https://signup.live.com/
accept-encoding: gzip, deflate, br
accept-language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7
cookie: amsc=b55INNzzHR5PZiPunWJJsx3fMAbVhvWRQlJkJfRh2zNI+jGPtSvnOYjXiJqnEctddyQyWNV64rFgnX9Qf57EA+YiA/VCFcqp6ogo+iXCvLBLpDne1H1QImvS5lgln9YT1eI5JbSQYm789c/XXcVi3mCEE9vKzuLq4CovhNTdvcBk/hXxtcDePtoNIZOjrfUSfP4/Gp34hMJFNK79iAo2rhl/WK9jO894h00DrAKnMEiA4Cd57LVili0DAOXInzcFSQ7TjRXBpNr2KoO2RB1ARd9sjjaQfycR/n6r6P5Fj+o=:2:3c

I only want to get canary: value and put it to request headers so when i do print(requestToWebsite.request.headers) i can see the value

Any help would be appreciated, Thank you.

Answer

Try this:

import redriverReq=str(driver.requests);ans= re.search('canary:(.*)content-type:', driverReq)
print(ans.group(1))
https://en.xdnf.cn/q/119558.html

Related Q&A

How to use windows as raspberry pi and connect the windows with another raspberry pi [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…

Python : Return the missing weekdays dates and assign rate next to missing date

Dates rates 7/26/2019 1.04 7/30/2019 1.0116 7/31/2019 1.005 8/1/2019 1.035 8/2/2019 1.01 8/6/2019 0.9886 8/7/2019 1.0048 8/8/2019 0.97 8/9/2019 0.9659 8/12/2019 0.965In …

How do I use a list or set as keys in file renaming

Is something like this possible? Id like to use a dictionary or set as the key for my file renamer. I have a lot of key words that id like to filter out of the file names but the only way iv found to …

How to change Python comment font style in the latest VS Code? [duplicate]

This question already has an answer here:How to change the font-style of code comments in vscode?(1 answer)Closed 6 months ago.Seems like with the latest VS Code update, all the comment font style has…

How to crop an image based on a complex criteria?

I have a set of similar images like the one below. I want to keep the portion of the image that is within the top red irregular rectangle (green arrows represent the space that I want to keep; anything…

Getting current video tag URL with selenium

Im trying to get the current html5 video tag URL using selenium (with python bindings):from selenium import webdriverdriver = webdriver.Chrome() driver.get(https://www.youtube.com/watch?v=9x6YclsLHN0)…

How to determine if two rows are identical (similar) if row 2 contains part of the info from row 1?

Hope you are having a good day. I am currently working with an extremely dirty dataframe containing First Name, Last Name, and Middle Name. One the issues that I am trying to resolve looks like below:F…

Cartopy fancy box

Hello I have been trying to plot data in a Orthographic projection. The data is plotted but I want the box to follow the data limits. Like in this example I am sharing form M_map[enter image descriptio…

discord.py - No DM sent to the user

I am making a discord.Client. I have a DM command that sends a DM to a specific user, but no message is sent to the user when the command is run, but a message is sent on the Context.channel. Here is m…

Improve CPU time of conditional statement

I have written an if-elif statement, which I believe not be very efficient:first_number = 1000 second_number = 700 switch = {upperRight: False,upperLeft: False,lowerRight: False,lowerLeft: False,middle…