title: Network capturing with Selenium/PhantomJS
body: <p>I want to capture the traffic to sites I'm browsing to using Selenium with python and since the traffic will be https using a proxy won't get me far.</p>
  
  <p>My idea was to run phantomJS with selenium to and use phantomJS to execute a script (not on the page using webdriver.execute_script(), but on phantomJS itself). I was thinking of the netlog.js script (from here <a href="https://github.com/ariya/phantomjs/blob/master/examples/netlog.js" rel="noreferrer">https://github.com/ariya/phantomjs/blob/master/examples/netlog.js</a>).</p>
  
  <p>Since it works like this in the command line</p>
  
  <pre><code>phantomjs --cookies-file=/tmp/foo netlog.js https://google.com
  </code></pre>
  
  <p>there must be a similar way to do this with selenium?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Solved it with browsermob-proxy.</p>
  
  <pre><code>pip3 install browsermob-proxy
  </code></pre>
  
  <p>Python3 code</p>
  
  <pre><code>from selenium import webdriver
  from browsermobproxy import Server
  
  server = Server(&lt;path to browsermob-proxy&gt;)
  server.start()
  proxy = server.create_proxy({'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
  
  service_args = ["--proxy=%s" % proxy.proxy, '--ignore-ssl-errors=yes']
  driver = webdriver.PhantomJS(service_args=service_args)
  
  proxy.new_har()
  driver.get('https://google.com')
  print(proxy.har)  # this is the archive
  # for example:
  all_requests = [entry['request']['url'] for entry in proxy.har['log']['entries']]
  </code></pre>