How to Setup Private Proxy with Selenium?

2019-02-20 07:21发布

问题:

I've been trying for days to setup a private proxy (with authentication) in Selenium using Firefox. However, no matter what I do I'v been unsuccessful.

Currently, I have tried the following two approaches and in both cases Firefox launches normally without any proxy.

        Proxy proxy = new Proxy();
        proxy.setHttpProxy(proxyHost + proxyPort);
        proxy.setSocksUsername(proxyUsername); 
        proxy.setSocksPassword(proxyPass);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability(CapabilityType.PROXY, proxy); 



        WebDriver driver = new FirefoxDriver(cap);

        driver.get("http://google.com");

I have also tried the following:

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", proxyHost);
    profile.setPreference("network.proxy.http_port", proxyPort);
    profile.setPreference("network.proxy.http", "user:pass@1.1.1.1");
    profile.setPreference("network.proxy.http_port", proxyPort);

    WebDriver driver = new FirefoxDriver(profile);

    driver.get("http://google.com");

How can I setup http private proxies (with user name and password in Selenium with Firefox)?

I am using Java.

Thanks

回答1:

You can try using browsermob proxy. Here you go for example



回答2:

Find solution:

proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': PROXY_HOST,
    'socksUsername': 'name',
    'socksPassword': 'pass'
    })

driver = webdriver.Firefox(proxy=proxy)