selenium-wire
selenium-wire copied to clipboard
how i can modify header driver
I want to change my header Http information but nothing happens with the below code. Please help me, what is the problem and how should I solve it? I want to be able to change the user's information on each visit, like the ModHeader extension.
`
import time
import os
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options # Import from seleniumwire
driver = webdriver.Chrome()
def interceptor(request):
request.headers['User-Agent'] = 'Mozilla/6.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36'
request.headers['sec-ch-ua'] = '"Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"'
request.headers['sec-ch-ua-mobile'] = '?0'
request.headers['sec-ch-ua-platform'] = 'os'
driver.request_interceptor = interceptor
driver.get("https://google.com")
for request in driver.requests:
print(request.headers)
print(request.response)
time.sleep(500)
my problem like this link in my driver data shows this
`
204
sec-ch-ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
sec-ch-ua-mobile: ?0
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
sec-ch-ua-arch: "x86"
sec-ch-ua-full-version: "111.0.5563.64"
sec-ch-ua-platform-version: "10.0.0"
sec-ch-ua-full-version-list: "Google Chrome";v="111.0.5563.64", "Not(A:Brand";v="8.0.0.0", "Chromium";v="111.0.5563.64"
sec-ch-ua-bitness: "64"
sec-ch-ua-model:
sec-ch-ua-wow64: ?0
sec-ch-ua-platform: "Windows"
accept: image/avif,image/webp,image/apng,image/svg+xml,image/,/*;q=0.8
x-client-data: CIv0ygE=
sec-fetch-site: same-origin
sec-fetch-mode: no-cors
sec-fetch-dest: image
referer: https://www.google.com/
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cookie: 1P_JAR=2023-03-12-22; AEC=ARSKqsLIZuIQCQoYlTRZfCg_tawXYvRiB1kDB8z1c0VRRrPAuD-iymrB8A; NID=511=rcB6Nv8Pzk7ZBKQzTcVBvMSzLfv0oqUwXU9b8LzBUfGVVEt1vkRAlZ5Lkg6fnKFbfb8jcf6tsYPVWRSe0wmd932NmGYf1vrDsxPp8nBEegoW_5nqEU2OCrKzLqDrBaBpsfeLOiXnJoz1ZJC6Cd2tqiO6XhTufWslhtromMGSRZc
User-Agent: Mozilla/6.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
sec-ch-ua: "Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"
sec-ch-ua-mobile: ?1
`
Please check the documentation, which says that if you wish to change a header(replacing with a new value), you first need to delete the existing one like this:
del request.headers['User-Agent']
https://github.com/wkeeling/selenium-wire#example-replace-an-existing-request-header
@masoudkhan Please close the issue in case it resolves your question.