Created
October 4, 2018 01:25
-
-
Save sureshsarda/d0553d8d3b63c3d301610a108c9e2c27 to your computer and use it in GitHub Desktop.
Download the network tab content when loading a page
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
import time | |
import pprint | |
from selenium import webdriver | |
from browsermobproxy import Server | |
class Browser: | |
def __init__(self): | |
self.server = None | |
self.profile = None | |
self.driver = None | |
self.proxy = None | |
self.options = {'port': 8090} | |
def start(self): | |
self.server = Server('/home/suresh/tools/browsermob-proxy-2.1.4/bin/browsermob-proxy', options=self.options) | |
self.server.start() | |
time.sleep(1) | |
self.proxy = self.server.create_proxy() | |
time.sleep(1) | |
service_args = ["--proxy-server=%s" % self.proxy.proxy] | |
self.profile = webdriver.FirefoxProfile() | |
selenium_proxy = self.proxy.selenium_proxy() | |
self.profile.set_proxy(selenium_proxy) | |
self.driver = webdriver.Firefox(firefox_profile=self.profile) | |
def stop(self): | |
self.server.stop() | |
self.driver.quit() | |
if __name__ == '__main__': | |
b = Browser() | |
b.start() | |
b.proxy.new_har("google") | |
b.driver.get("http://sureshsarda.in") | |
pprint.pprint(b.proxy.har, indent=4) # returns a HAR JSON blob | |
b.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment