如何在webdriver的HTMLUNIT中使用socks代理?
这段代码:
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代理呢?
1 个回答
1
这可真不简单 =(
最后在这里找到了答案:在Python中使用代理运行Selenium Webdriver
...
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)
...