Last active
October 31, 2017 23:13
-
-
Save elmarcoh/7799354 to your computer and use it in GitHub Desktop.
Selenium + Browsermob proxy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By default where the HAR file will get stored?