Skip to content

Instantly share code, notes, and snippets.

@elmarcoh
Last active October 31, 2017 23:13
Show Gist options
  • Save elmarcoh/7799354 to your computer and use it in GitHub Desktop.
Save elmarcoh/7799354 to your computer and use it in GitHub Desktop.
Selenium + Browsermob proxy example
"""
Selenium webdriver + BrowserMob proxy example
First, you have to download browsermob:
wget --no-check-certificate https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-9-bin.zip
unzip inside the directory you are running this
pip install selenium browsermob-proxy
done!
"""
from selenium import webdriver
from browsermobproxy import Server
import os
root_path = os.path.abspath(os.path.dirname(__file__))
server = Server(os.path.join(root_path, "browsermob-proxy-2.0-beta-9/bin/browsermob-proxy"))
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("google")
driver.get("http://www.google.cl")
#print proxy.har
#import pdb; pdb.set_trace()
print "Requests were made to the following URLS:"
print "========================================="
for entry in proxy.har['log']['entries']:
print entry['request']['url']
server.stop()
driver.quit()
@QAInsights
Copy link

By default where the HAR file will get stored?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment