Setting up proxy with selenium / python
<p>I am using selenium with python.
I need to configure a proxy.</p>

<p>It is working for HTTP but not for HTTPS.</p>

<p>The code I am using is:</p>

<pre><code># configure firefox
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", '11.111.11.11')
profile.set_preference("network.proxy.http_port", int('80'))
profile.update_preferences()

# launch
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://www.iplocation.net/find-ip-address')
</code></pre>

<p>Also. Is there a way for me to completely block any outgoing traffic from my IP and restrict it ONLY to the proxy IP so that I don't accidently mess up the test/stats by accidently switching from proxy to direct connection?</p>

<p>Any tips would help!
Thanks :)</p>

<p>Check out <a href="https://github.com/AutomatedTester/browsermob-proxy-py" rel="nofollow">browsermob proxy</a> for setting up a proxies for use with <code>selenium</code></p>

<pre><code>from browsermobproxy import Server
server = Server("path/to/browsermob-proxy")
server.start()
proxy = server.create_proxy()

from selenium import webdriver
profile  = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)


proxy.new_har("google")
driver.get("http://www.google.co.uk")
proxy.har # returns a HAR JSON blob

server.stop()
driver.quit()
</code></pre>

<p>You can use a remote proxy server with the <code>RemoteServer</code> class.</p>

<blockquote>
  <p>Is there a way for me to completely block any outgoing traffic from my IP and restrict it ONLY to the proxy IP</p>
</blockquote>

<p>Yes, just look up how to setup proxies for whatever operating system you're using. Just use caution because some operating systems will ignore proxy rules based on certain conditions, for example, if using a VPN connection.</p>

python selenium proxy