Подтвердить что ты не робот

Webdriver и прокси-сервер для firefox

Есть ли способы установить параметры прокси-сервера Firefox? Я нашел здесь информацию о FoxyProxy, но когда Selenium работает, плагины неактивны в окне.

4b9b3361

Ответ 1

Посмотрите страницу документации.

Настройка существующего профиля Firefox

Вам нужно изменить настройки профиля "network.proxy.http" и "network.proxy.http_port".

FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("network.proxy.http", "localhost");
profile.addAdditionalPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);

Ответ 2

Значение для network.proxy.http_port должно быть целым (не использовать кавычки), а network.proxy.type должно быть установлено как 1 (ProxyType.MANUAL, настройки ручного прокси-сервера)

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", 3128);
WebDriver driver = new FirefoxDriver(profile);

Ответ 3

Мне было весело с этой проблемой в течение нескольких дней, и мне было трудно найти ответ для HTTPS, поэтому здесь я беру для Java:

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", "proxy.domain.example.com");
    profile.setPreference("network.proxy.http_port", 8080);
    profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");
    profile.setPreference("network.proxy.ssl_port", 8080);
    driver = new FirefoxDriver(profile);

Gotchas здесь: введите только домен, а не http://proxy.domain.example.com, имя свойства .ssl, а не .https

Теперь я получаю еще больше удовольствия, пытаясь заставить его принять мои самоподписанные сертификаты...

Ответ 4

Изменен API WebDriver. Текущий фрагмент для установки прокси-сервера -

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);

Ответ 5

Если у вас есть URL автоконфигурации -

        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("network.proxy.type", 2);
        firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://www.etc.com/wpad.dat");
        firefoxProfile.setPreference("network.proxy.no_proxies_on", "localhost");
        WebDriver driver = new FirefoxDriver(firefoxProfile);

Ответ 6

Просто добавьте к приведенным выше решениям.

Добавление списка возможностей (целочисленные значения) для "network.proxy.type".

0 - Direct connection (or) no proxy. 

1 - Manual proxy configuration

2 - Proxy auto-configuration (PAC).

4 - Auto-detect proxy settings.

5 - Use system proxy settings. 

Итак, исходя из нашего требования, значение "network.proxy.type" должно быть установлено, как указано ниже.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
WebDriver driver = new FirefoxDriver(profile);

Ответ 7

Для URL-адресов, основанных на PAC

 Proxy proxy = new Proxy();
 proxy.setProxyType(Proxy.ProxyType.PAC);
 proxy.setProxyAutoconfigUrl("http://some-server/staging.pac");
 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setCapability(CapabilityType.PROXY, proxy);
 return new FirefoxDriver(capabilities);

Надеюсь, это поможет.

Ответ 8

Здесь приведен пример java с помощью DesiredCapabilities. Я использовал его для прокачки тестов селена в jmeter. (интересовался только HTTP-запросами)

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

String myProxy = "localhost:7777";  //example: proxy host=localhost port=7777
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY,
                           new Proxy().setHttpProxy(myProxy));
WebDriver webDriver = new FirefoxDriver(capabilities); 

Ответ 9

Прокси Firefox: JAVA

String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();

proxy.setHttpProxy(PROXY)setFtpProxy(PROXY).setSslProxy(PROXY);

DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability(CapabilityType.PROXY, proxy); 

WebDriver driver = new FirefoxDriver(cap);

Ответ 10

Есть еще одно решение, которое я искал, потому что у него были проблемы с таким кодом (он установил системный прокси в firefox):

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "8080");
driver = new FirefoxDriver(profile);

Я предпочитаю это решение, оно заставляет ручную настройку прокси в firefox. Для этого используйте объект org.openqa.selenium.Proxy для настройки Firefox:

FirefoxProfile profile = new FirefoxProfile();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("localhost:8080");
profile.setProxyPreferences(localhostProxy);
driver = new FirefoxDriver(profile);

если это может помочь...

Ответ 11

FirefoxProfile profile = new FirefoxProfile();
String PROXY = "xx.xx.xx.xx:xx";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy=PROXY;
proxy.FtpProxy=PROXY;
proxy.SslProxy=PROXY;
profile.SetProxyPreferences(proxy);
FirefoxDriver driver = new FirefoxDriver(profile);

Это для С#

Ответ 12

Настройки → Дополнительно → Сеть → Соединение (настройте, как Firefox подключается к Интернету)