0

I am using selenium with python. I need to configure a proxy.

It is working for HTTP but not for HTTPS.

The code I am using is:

# 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') 

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?

Any tips would help! Thanks :)

    2 Answers 2

    1

    Check out browsermob proxy for setting up a proxies for use with selenium

    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() 

    You can use a remote proxy server with the RemoteServer class.

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

    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.

    2
    • Why is this required? Is selenium not able to provide proxy on its own? Why do we need browsermobproxy? I appreciate the information so far, will do some reading. Thanks :)
      – willer2k
      CommentedOct 19, 2016 at 2:16
    • It is useful because you have access to the HAR data from the proxy server, which would offer an assurance the proxy is being used, among other benefits. To get this data otherwise would be a somewhat involved process. Browsermob proxy abstracts this with a uniform API.
      – sytech
      CommentedOct 19, 2016 at 2:50
    0

    Here is the answer of it. You can try this one.

    for PROXY you can use any proxy host with port.

    https://stackoverflow.com/a/48498403/5533485

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.