启动selenium时,怎样加入firefox网络代理,在线等
答案:2 悬赏:70 手机版
解决时间 2021-03-19 19:07
- 提问者网友:难遇难求
- 2021-03-19 10:34
启动selenium时,怎样加入firefox网络代理,在线等
最佳答案
- 五星知识达人网友:妄饮晩冬酒
- 2021-03-19 10:53
String proxyIp = "10.158.140.94";
int proxyPort = 80;
FirefoxProfile profile = new FirefoxProfile();
// 使用代理
profile.setPreference("network.proxy.type", 1);
// http协议代理配置
profile.setPreference("network.proxy.http", proxyIp);
profile.setPreference("network.proxy.http_port", proxyPort);
profile.setPreference("network.proxy.ssl", proxyIp);
profile.setPreference("network.proxy.ssl_port", proxyPort);
// 所有协议公用一种代理配置,如果单独配置,这项设置为false
profile.setPreference("network.proxy.share_proxy_settings", true);
// 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯
profile.setPreference("network.proxy.no_proxies_on", "localhost");
// 以代理方式启动firefox
FirefoxDriver driver = new FirefoxDriver(profile);
上面是之前一个网友使用的解决方案,你可以试一下是否可行
int proxyPort = 80;
FirefoxProfile profile = new FirefoxProfile();
// 使用代理
profile.setPreference("network.proxy.type", 1);
// http协议代理配置
profile.setPreference("network.proxy.http", proxyIp);
profile.setPreference("network.proxy.http_port", proxyPort);
profile.setPreference("network.proxy.ssl", proxyIp);
profile.setPreference("network.proxy.ssl_port", proxyPort);
// 所有协议公用一种代理配置,如果单独配置,这项设置为false
profile.setPreference("network.proxy.share_proxy_settings", true);
// 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯
profile.setPreference("network.proxy.no_proxies_on", "localhost");
// 以代理方式启动firefox
FirefoxDriver driver = new FirefoxDriver(profile);
上面是之前一个网友使用的解决方案,你可以试一下是否可行
全部回答
- 1楼网友:从此江山别
- 2021-03-19 10:58
firefoxprofile profile = new firefoxprofile();
profile.setpreference("network.proxy.type", 1);
profile.setpreference("network.proxy.http", "192.168.11.254");
profile.setpreference("network.proxy.http_port", 8080);
profile.setpreference("network.proxy.share_proxy_settings", true);
profile.setpreference("network.proxy.no_proxies_on", "localhost");
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯