browsermob-proxy icon indicating copy to clipboard operation
browsermob-proxy copied to clipboard

How to use browsermob with python-selenium behind a corporate proxy?

Open Laurauma opened this issue 5 years ago • 0 comments

My test environment is under a corporate proxy ("proxy.ptbc.std.com:2538").I want to open a particular video on YoTube for a period of time (eg 200 seconds) and capture the har file for each visit, the process is repeated several times for a massive test. I have tried different examples found here but the firefox / chrome browsers do not connect to the internet because they are behind the proxy.

How can run "python-selenium + browsermobproxy" behind a corporate proxy and capture the har file for each instance.

Example code:

from browsermobproxy import Server
server = Server("C:\\Utility\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy")
server.start()
proxy = server.create_proxy()

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={}".format(proxy.proxy))
driver = webdriver.Chrome(options=chrome_options)

proxy.new_har("google")
driver.get("http://www.google.co.in")
proxy.har # returns a HAR JSON blob

server.stop()
driver.quit()

Any help would be appreciated

Laurauma avatar May 30 '20 21:05 Laurauma