set proxy in selenium

54 Views Asked by At

i have an issue with the selenium, i want to set proxy for my driver but it dosent work. what is the problem?

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType


PROXY = "51.15.78.38"
proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY,
    'noProxy': ''
})

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()),
                            proxy=proxy)

driver.get('https://whatismyipaddress.com/')


any hint will be helpful.

when i go to the https://whatismyipaddress.com/ my ip address dosent change!

1

There are 1 best solutions below

2
Eirik Lykken On

Proxy port is missing. If your port is 8080, code should be:

PROXY = "51.15.78.38:8080"

Also, this has been deprecated, current approach using Options would be:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options

PROXY = "51.15.78.38:8080"  # Assuming proxy port 8080
# Set up Firefox Options 
firefox_options = Options()
firefox_options.add_argument('--proxy-server=%s' % PROXY)

firefox_service = FirefoxService(executable_path=GeckoDriverManager().install())
driver = webdriver.Firefox(service=firefox_service, options=firefox_options)

driver.get('https://whatismyipaddress.com/')