How do I set header when using browsermob proxy selenium Python

124 views Asked by At

I am having troubles setting a custom header when using browsermob proxy with selenium. I only see examples using Java, but none for Python. I want to know how to do so using browsermob proxy and Selenium-wire, and the difference/use cases between both.

If I can get an implementation of both (using Python and ChromeOptions) in one answer that would be great.

I have installed bmp and set it up following this post:

https://stackoverflow.com/a/48266639/18346591

My current code looks like this

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from collections import Counter
from browsermobproxy import Server

server = Server('C:\\Users\\HP\\Documents\\browsermob-proxy-2.1.4-bin\\bin\\browsermob-proxy')
server.start()
proxy = server.create_proxy()
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server={0}".format(proxy.proxy))
options.add_experimental_option('detach', True)
options.add_argument("--disable-proxy-certificate-handler")
driver = webdriver.Chrome(options=options)

I am not trying to add a proxy. At least not yet. I just got a bit confused.

Places I have checked:

And many more...

0

There are 0 answers