0

Does anyone have any working code for python selenium, firefox, proxy server?

There are many methods that are described on various solutions but none of them seem to work.

I'm trying to create headless firefox, then call "whatismyip.com" to test the IP. However, I always get current IP.

opts = FirefoxOptions()
opts.add_argument("--headless")
myProxy = "xxx.xxx.xxx.xxx:xxxx"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
            "httpProxy": myProxy,
            "sslProxy": myProxy,
            "proxyType": "MANUAL",
        } 
browser = webdriver.Firefox(options=opts)
browser.get( 'https://www.whatismyip.com/')
charlesw001
  • 144
  • 1
  • 3
  • AFAIK capabilities have been removed from the latest selenium release. This answer https://stackoverflow.com/questions/11450158/how-do-i-set-proxy-for-chrome-in-python-webdriver should work for firefox and chrome? – dosas Jul 01 '22 at 18:19

1 Answers1

0

It would be helpful to have more information: What versions you are using and the setup. The response that was provided fix is for Chrome and not Firefox. If you are using 4.0 selenium then the DesiredCapabilities has been deprecated Legacy Selenium Desired Capabilities. The options and services should be used. The following worked with Seleinum 4.0 in and latest python library. Using binary_location with portable Firefox and Windows 10 OS. The following will change all the proxy options just remove the ones' you do not want.

from selenium import webdriver
from selenium.webdriver.common.proxy import *
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

options=Options()
s = Service('c:\\webdriver\\geckodriver.exe')
options.binary_location = r'C:\Firefox64\firefox.exe' # FF installed locaiton

myProxy = "86.111.144.194:3128"
options.proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    "socksVersion": 5,
    'httpProxy': myProxy,    
    'sslProxy': myProxy,
    "socksProxy": myProxy,
    'noProxy':''})


driver = webdriver.Firefox(service=s, options=options)
driver.set_page_load_timeout(30)
driver.get('http://ifconfig.io')

I would use a different service to check the IP as some will want additional verification if going through TOR.