有没有办法设置Firefox的代理设置?我在这里找到了关于FoxyProxy的信息,但当Selenium工作时,窗口中的插件未被激活。
有没有办法设置Firefox的代理设置?我在这里找到了关于FoxyProxy的信息,但当Selenium工作时,窗口中的插件未被激活。
有没有办法设置Firefox的代理设置?我在这里找到了关于FoxyProxy的信息,但当Selenium工作时,窗口中的插件未被激活。
有没有办法设置Firefox的代理设置?我在这里找到了关于FoxyProxy的信息,但当Selenium工作时,窗口中的插件未被激活。
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);
我刚刚花了几天时间解决这个问题,对于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);
需要注意的是:只需输入域名而不是http://proxy.domain.example.com
,属性名为.ssl
而非.https
现在,我正在尝试让它接受我的自签名证书,这真是太有趣了...
请查看文档页面。
调整现有的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);
仅补充上述解决方案,
添加“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);
network.proxy.type
的可能取值列表是什么? - robertspierreFirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);
以下是使用DesiredCapabilities
的Java示例。我将其用于将Selenium测试注入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);
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);
针对基于PAC的URL
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);
我希望这可以帮助您。
http://code:Blue%4019@proxypath.pac
,但无法加载任何页面。 - codeomnitrixfrom selenium import webdriver
PROXY = "<HOST:PORT>"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
"httpProxy": PROXY,
"ftpProxy": PROXY,
"sslProxy": PROXY,
"proxyType": "MANUAL",
}
with webdriver.Firefox() as driver:
# Open URL
driver.get("https://selenium.dev")
火狐代理: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);
profile.setPreference("network.proxy.http", "user:pass@1.1.1.1:2874")
但显然它不起作用。 - Shanewebdriver
在我当时尝试做的大量工作中太笨重了,所以我转向使用requests
(一个Python库)进行纯HTTP/HTTPS
请求来完成我的工作。 - Shane