将 http 代理与 selenium Geckodriver 一起使用
using http proxy with selenium Geckodriver
我尝试了一些方法,但没有一个起作用。有人有使用 HTTP 代理和 Geckodriver for Selenium 3 的工作示例吗?我正在使用 Java 绑定
这是我试过的
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
Proxy proxy = new Proxy();
proxy.setHttpProxy("proxyip:proxyport");
capabilities.setCapability("proxy", proxy);
System.setProperty("webdriver.gecko.driver", "C:\geckodriver-v0.16.1-win64\geckodriver.exe");
WebDriver driver = new FirefoxDriver(capabilities);
要使用 Firefox 浏览器启用 proxy,您需要创建一个 新配置文件 并通过它按如下方式发送给驱动程序:
正在设置 HTTP 代理:
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);
正在设置 SSL 代理:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.ssl", "localhost");
profile.setPreference("network.proxy.ssl_port", 3128);
WebDriver driver = new FirefoxDriver(profile);
如果需要授权使用代理,那么selenium是做不到的。由于 selenium 不支持使用要求密码的警报。我为 Firefox 写了一个 add-on,你可以用它解决代理和 cookie 的问题以及 headers。
https://github.com/alexsok-bit/selenium_helper
您可以使用发布目录中的 add-on,它已经签名
我尝试了一些方法,但没有一个起作用。有人有使用 HTTP 代理和 Geckodriver for Selenium 3 的工作示例吗?我正在使用 Java 绑定
这是我试过的
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
Proxy proxy = new Proxy();
proxy.setHttpProxy("proxyip:proxyport");
capabilities.setCapability("proxy", proxy);
System.setProperty("webdriver.gecko.driver", "C:\geckodriver-v0.16.1-win64\geckodriver.exe");
WebDriver driver = new FirefoxDriver(capabilities);
要使用 Firefox 浏览器启用 proxy,您需要创建一个 新配置文件 并通过它按如下方式发送给驱动程序:
正在设置 HTTP 代理:
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);
正在设置 SSL 代理:
FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.ssl", "localhost"); profile.setPreference("network.proxy.ssl_port", 3128); WebDriver driver = new FirefoxDriver(profile);
如果需要授权使用代理,那么selenium是做不到的。由于 selenium 不支持使用要求密码的警报。我为 Firefox 写了一个 add-on,你可以用它解决代理和 cookie 的问题以及 headers。
https://github.com/alexsok-bit/selenium_helper
您可以使用发布目录中的 add-on,它已经签名