我将代理设置为chrome驱动程序
ChromeOptions optionsMap = new ChromeOptions();
optionsMap.addArguments("--headless");
optionsMap.addArguments("--user-agent=Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36");
Proxy proxy = new Proxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setHttpProxy(proxyValue);
optionsMap.setCapability(CapabilityType.PROXY, proxy);但是流量来自本地IP地址。我希望流量来自代理服务器。你能解决这个问题吗。为了测试,我将chrome驱动程序代理设置为不同的ip,而不是本地地址,并运行网站https://icanhazip.com/以了解ip。该网站仍显示本地IP。
我使用以下代码构建了chrome驱动程序
String driverAbsPath = new File(seleniumChromeDriverPath).getAbsolutePath().replace("/~/", "/");
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(driverAbsPath))
.usingAnyFreePort()
.build();
optionsMap.merge(chromecapabilities);
driver = new ChromeDriver(service, optionsMap);发布于 2020-03-11 02:33:02
尝试将ip地址添加到代理端的X-Forwarded-For标头中:
proxy.addHeader("X-Forwarded-For", "1.2.3.4")https://stackoverflow.com/questions/60621759
复制相似问题