0

Following this answer, I changed the proxy of my driver like so:

from selenium import webdriver

def set_proxy(driver, http_addr='', http_port=0, ssl_addr='', ssl_port=0, socks_addr='', socks_port=0):

    driver.execute("SET_CONTEXT", {"context": "chrome"})

    try:
        driver.execute_script("""
          Services.prefs.setIntPref('network.proxy.type', 1);
          Services.prefs.setCharPref("network.proxy.http", arguments[0]);
          Services.prefs.setIntPref("network.proxy.http_port", arguments[1]);
          Services.prefs.setCharPref("network.proxy.ssl", arguments[2]);
          Services.prefs.setIntPref("network.proxy.ssl_port", arguments[3]);
          Services.prefs.setCharPref('network.proxy.socks', arguments[4]);
          Services.prefs.setIntPref('network.proxy.socks_port', arguments[5]);
          """, http_addr, http_port, ssl_addr, ssl_port, socks_addr, socks_port)

    finally:
        driver.execute("SET_CONTEXT", {"context": "content"})


driver = webdriver.Firefox()

set_proxy(driver, http_addr="212.35.56.21", http_port=8080)

driver.get("https://google.fr/")

It ran, but I'm not sure if the firefox browser is using the proxy that I gave to it or not. I thus have two questions:

  • Is this the correct way to change the proxy?
  • How can I get the value of the current proxy used by the driver?
Metariat
  • 522
  • 3
  • 16

0 Answers0