0

编码:

cap = DesiredCapabilities.HTMLUNITWITHJS
driver = webdriver.Remote("http://localhost:%i/wd/hub" % HTMLUNIT_PORT, cap)

在初始化之前尝试这样做:

...
cap['proxy']['proxyType'] = 'manual'
cap['socksProxy'] = ip + ':' + str(port)
...

但它似乎没有用 - IP 保持不变。

如何在 webdriver 和 htmlunit 中使用 socks 代理?

4

1 回答 1

1

这不容易=(

终于在这里找到了:Running Selenium Webdriver with a proxy in Python

...
caps = webdriver.DesiredCapabilities.HTMLUNITWITHJS
PROXY = '127.0.0.1:9050'
caps['proxy'] = {
    "socksProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "noProxy":None,
    "proxyType":"MANUAL",
    "class":"org.openqa.selenium.Proxy",
    "autodetect":False
}

driver = webdriver.Remote(desired_capabilities=caps)
...
于 2014-05-07T04:49:12.353 回答