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

2
  • > Similar question: stackoverflow.com/questions/18719980/… Commented Aug 18, 2018 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) Commented Aug 18, 2018 at 13:49

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.