【问题标题】:How to Setup Private Proxy with Selenium?如何使用 Selenium 设置私有代理?
【发布时间】:2015-06-05 20:10:43
【问题描述】:

我几天来一直在尝试使用 Firefox 在 Selenium 中设置私有代理(带有身份验证)。但是,无论我做什么,我都没有成功。

目前,我尝试了以下两种方法,在这两种情况下,Firefox 都能正常启动没有任何代理。

        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");

我也尝试了以下方法:

    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");

如何设置 http 私有代理(在 Selenium 和 Firefox 中使用用户名和密码)?

我正在使用 Java。

谢谢

【问题讨论】:

    标签: java firefox selenium proxy


    【解决方案1】:
    const {Builder, By, Key, until} = require('selenium-webdriver');
    const proxy = require('selenium-webdriver/proxy');
    (async function example(){
      let driver = await new Builder().forBrowser('firefox').setProxy(proxy.manual({
        http: 'zproxy.lum-superproxy.io:22225',
        https: 'zproxy.lum-superproxy.io:22225'
      })).build()
      try {
        await driver.get('http://lumtest.com/myip.json');
        driver.switchTo().alert()
          .sendKeys('lum-customer-USERNAME-zone-YOURZONE'+Key.TAB+'PASSWORD');
        driver.switchTo().alert().accept();
      } finally {
        await driver.quit();
      }
    })();
    

    当我使用 Luminati 代理 Selenium 时,这里是 my sample code。

    【讨论】:

      【解决方案2】:

      您可以尝试使用browsermob proxy。 给你example

      【讨论】:

        【解决方案3】:

        寻找解决方案:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-19
          • 2019-04-04
          相关资源
          最近更新 更多