I'm playing with Browsermob Proxy and a simple script with it (below) works extremely slow. I guess, it is the time it takes to start a new server.
If this is the case, is there a way to start a server to use it between different script executions?
Or if this is not the case, what can be slowing down my script?
from browsermobproxy import Server
from selenium.webdriver.firefox.options import Options
from selenium import webdriver
import json
server = Server("/anaconda3/lib/python3.7/site-packages/browsermobproxy/browsermob-proxy-2.1.4/bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()
print(1)
profile = webdriver.FirefoxProfile(profile_directory=r'./')
print(2)
profile.set_proxy(proxy.selenium_proxy())
print(4)
opts = Options()
opts.headless = True
driver = webdriver.Firefox(profile, executable_path=r'./geckodriver', options=opts)
print(5)
proxy.new_har()
driver.get("http://value.to")
proxy.har # returns a HAR JSON blob
#print(proxy.har)
print("analytics in value.to:")
for entry in proxy.har["log"]["entries"]:
if "google-analytics" in entry["request"]["url"]:
print(entry["request"]["url"])
print("\n\n\n")
proxy.new_har()
driver.get("http://insightwhale.com")
proxy.har # returns a HAR JSON blob
#print(proxy.har)
print("analytics in insightwhale:")
for entry in proxy.har["log"]["entries"]:
if "google-analytics" in entry["request"]["url"]:
print(entry["request"]["url"])
print(json.dumps(proxy.har, indent=4, sort_keys=True))
file = open("____tmp.txt", "w")
file.write(json.dumps(proxy.har, indent=4, sort_keys=True))
file.close()
server.stop()
driver.quit()