0

I'm trying to set up a proxy for Selenium and Firefox (using Python). I have seen many tutorials and posts how to do it, but most are outdated or don't work for me.

I've been trying to use:

ua = UserAgent()
    userAgent = ua.random

    options = Options()
    options.set_preference('general.useragent.override', userAgent)

    options.set_preference('network.proxy.type', 1)
    options.set_preference('network.proxy.http', proxy['ip'])
    options.set_preference('network.proxy.http_port', proxy['port'])
    options.set_preference('network.proxy.ssl', proxy['ip'])
    options.set_preference('network.proxy.ssl_port', proxy['port'])
    options.set_preference('network.proxy.socks_remote_dns', False)

    service = Service(executable_path='../geckodriver-v0.30.0-linux64')
    driver = webdriver.Firefox(service=service, options=options)
    driver.get('https://www.expressvpn.com/what-is-my-ip')

The website https://www.expressvpn.com/what-is-my-ip shows my home IP, so proxying doesn't work.

I also tried:

ua = UserAgent()
    userAgent = ua.random

    options = Options()
    options.set_preference('general.useragent.override', userAgent)

    str_proxy = f"{proxy['ip']}:{proxy['port']}"
    
    my_proxy = Proxy({
        'proxyType': ProxyType.MANUAL,
        'httpProxy': str_proxy,
        'ftpProxy': str_proxy,
        'sslProxy': str_proxy,
    })

    service = Service(executable_path='../geckodriver-v0.30.0-linux64')
    driver = webdriver.Firefox(service=service, options=options, proxy=my_proxy)
    driver.get('https://www.expressvpn.com/what-is-my-ip')

I also tried:

ua = UserAgent()
    userAgent = ua.random

    options = Options()
    options.page_load_strategy = 'eager'
    options.set_preference('general.useragent.override', userAgent)

    str_proxy = f"{proxy['ip']}:{proxy['port']}"

    webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
        "httpProxy": str_proxy,
        "ftpProxy": str_proxy,
        "sslProxy": str_proxy,
        "proxyType": "MANUAL",

    }

    service = Service(executable_path='../geckodriver-v0.30.0-linux64')
    driver = webdriver.Firefox(service=service, options=options)
    driver.get('https://www.expressvpn.com/what-is-my-ip')

The str_proxy is something like: 8.214.41.50:80

All of the above ways don't work. So, how do I use proxy with Selenium 4 python and Firefox?

2

0

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.