Selenium Chrome Driver Socks代理配置

22

我在为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代理。

我该怎么做?


你是如何解决这个错误的? - JobaDiniz
@JobaDiniz 请查看此答案:https://dev59.com/FGEh5IYBdhLWcg3wYSk2#28891213 - Stephan
3个回答

31
    ChromeOptions options = new ChromeOptions();
    options.add_argument("--proxy-server=socks5://" + host + ":" + port);
    WebDriver driver = new ChromeDriver(options);

8
你尝试使用过这个Chromium参数吗?
--proxy-server="socks5://host:port"

0
from selenium.webdriver.firefox.options import Options as ff_options
random_proxy = "142.54.61.98:120"
options = ff_options()
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": random_proxy,
    "ftpProxy": random_proxy,
    "sslProxy": random_proxy
}
profile = webdriver.FirefoxProfile()
profile.set_preference("media.peerconnection.enabled", False)
profile.set_preference("media.navigator.enabled", False)
# profile.set_preference("general.useragent.override", user_agent)
profile.update_preferences()

driver = webdriver.Firefox(capabilities=firefox_capabilities, firefox_profile=profile,
                           firefox_options=options)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接