python – Exporting a .HAR with selenium webdriver

I’m trying to export a .HAR file from a webdriver page

from browsermobproxy import Server
from selenium import webdriver
import os
import json
from urllib.parse import urlparse

server = Server("browsermob-proxy-2.1.4/bin/browsermob-proxy.bat")
server.start()
proxy = server.create_proxy()

chromedriver = "chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
url = urlparse.urlparse (proxy.proxy).path
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={0}".format(url))
driver = webdriver.Chrome(chromedriver,chrome_options =chrome_options)
proxy.new_har("http://stackoverflow.com", options={'captureHeaders': True})
driver.get("http://stackoverflow.com")    
result = json.dumps(proxy.har, ensure_ascii=False)
print(result)
proxy.stop()    
driver.quit()

But when I run this, I get the error

browsermobproxy.exceptions.ProxyServerError: The Browsermob-Proxy server process failed to start. Check <_io.TextIOWrapper name="C:\\Users\\USER\\Desktop\\PROJECT\\server.log" mode="w" encoding='cp1252'>for a helpful error message.

I’ve gone through everything and can’t find the issue.

Read more here: Source link