I need help configuring proxy options for a PhantomJS headless session using Python and Selenium. My goal is to correctly adjust the browser’s network settings, similar to a Firefox profile, to work behind a proxy. I am currently running Python 2.7, Selenium 3.0, and PhantomJS 1.9.7. Below is an example of my revised configuration code:
from selenium import webdriver
def init_driver():
print('Initializing Selenium driver...')
global browser_instance
if browser_instance is None:
ff_profile = webdriver.FirefoxProfile()
ff_profile.accept_untrusted_certs = True
ff_profile.set_preference('network.proxy.mode', 1)
ff_profile.set_preference('network.proxy.http', 'proxy-server.example.net')
ff_profile.set_preference('network.proxy.https', 'proxy-server.example.net')
ff_profile.set_preference('network.proxy.ssl', 'proxy-server.example.net')
ff_profile.set_preference('network.proxy.http_port', 8080)
ff_profile.set_preference('network.proxy.https_port', 8080)
ff_profile.set_preference('network.proxy.ssl_port', 8080)
ff_profile.update_preferences()
browser_instance = webdriver.Firefox(firefox_profile=ff_profile)
browser_instance.maximize_window()
yield browser_instance
browser_instance.quit()