0

I hope I find you well today.

Background Information: Today I was coding a program and wanted to add proxy support. So far I have managed to connect using Localhost. However I want to add support for proxies that have a username and password (Format is IP Address:Port:Username:Password) in order to make as many accounts as possible. So far the code I have used is:

from selenium import webdriver

PROXY_HOST = "107.178.214.243"
PROXY_PORT = "3128"
USERNAME = "test" 
PASSWORD = "test"

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.socks_username", USERNAME)
profile.set_preference("network.proxy.socks_password", PASSWORD)

profile.update_preferences()

# executable_path  = define the path if u don't already have in the PATH 
system variable. 
browser = webdriver.Firefox(firefox_profile=profile)
browser.get('https://whatismyipaddress.com/')
browser.maximize_window()

Now this is only for 1 proxy and it isn't headless (I know). I wanted to see what happened before I made it headless.

What Happens: It opens the Firefox browser just fine and goes to the site as well. However it doesn't actually use the proxy. It just uses my localhost.

What I need: I need it to use the proxy. Also would like it to be able to pick up proxies from a text file and use them

warkun5400
  • 53
  • 8
  • > Similar question: https://stackoverflow.com/questions/18719980/proxy-selenium-python-firefox – Xnkr Aug 18 '18 at 13:42
  • Thanks for your help. However skimming over that post, it seems to me that they do not offer a solution for authenticated proxies (proxies that have a username and password) – warkun5400 Aug 18 '18 at 13:49

1 Answers1

0

following method can be used to get driver with a proxy

def get_driver(PROXY):

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX

firefox_capabilities['proxy'] = {"proxyType": "MANUAL", "httpProxy": PROXY, "ftpProxy": PROXY, "sslProxy": PROXY }
fp = webdriver.FirefoxProfile()

options = Options()
options.add_argument("--headless")

fp.update_preferences()
driver  = webdriver.Firefox(firefox_options=options,capabilities=firefox_capabilities, executable_path=geckodriver_path,firefox_profile=fp)
driver.set_window_size(2400,1980)

return driver
hakamairi
  • 4,464
  • 4
  • 30
  • 53
krishna chandak
  • 391
  • 5
  • 6