我在为Chrome驱动程序设置 socks 代理时遇到麻烦
Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.MANUAL);
proxy.setAutodetect(false);
proxy.setSocksProxy(ProxyHelper.PROXY_HOST + ":" + ProxyHelper.PROXY_PORT);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver chromeDriver = new ChromeDriver(capabilities);
此配置提供:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot parse capability: proxy from unknown error: proxyType is 'manual' but no manual proxy capabilities were found
我认为它希望我填写http,ftp和ssl代理。但是如果我填满它们,错误不会引发,但是我的代理也无法正常工作,因为它尝试像HTTP代理而不是 socks 代理一样使用它。
我能做什么?
最佳答案
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=socks5://" + host + ":" + port);
WebDriver driver = new ChromeDriver(options);
关于selenium - Selenium Chrome 驱动程序 socks 代理配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22481389/