使用selenium 3.8.1设置chrome代理的问题

时间:2018-01-23 22:23:23

标签: python google-chrome selenium-webdriver proxy

我曾经在Chrome上设置代理,如下面的代码,但当我更新到selenium 3.8.1代理停止工作,我没有得到任何错误它只是没有使用代理服务器,我不知道为什么。我的chromedriver也是最新的。

options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=192.99.55.120:3128')
driver = webdriver.Chrome(executable_path='C:\chromedriver_win32\chromedriver.exe', chrome_options=options)
driver.get("http://google.com/")

希望收到任何建议,也许是为chromedriver设置代理的替代方法。

3 个答案:

答案 0 :(得分:0)

options.add_argument('--proxy-server="http=192.99.55.120:3128;https=192.99.55.120:3128"')

还尝试使用这些参数直接运行您的chrome二进制文件以查看它是否有效

chrome.exe --proxy-server="http=192.99.55.120:3128"

答案 1 :(得分:0)

如果有人仍然感兴趣,这就是我最终解决问题的方法

from selenium.webdriver import Proxy
settings = {
        "httpProxy": "192.99.55.120:3128",
        "sslProxy": "192.99.55.120:3128"
    }
proxy = Proxy(settings)
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME.copy()
cap['platform'] = "WINDOWS"
cap['version'] = "10"
proxy.add_to_capabilities(cap)

from selenium.webdriver.chrome.webdriver import WebDriver as ChromeDriver
driver = ChromeDriver(desired_capabilities=cap, executable_path='C:\chromedriver_win32\chromedriver.exe')

答案 2 :(得分:0)

如果导航器要求提供代理的凭据用户名和密码,而您需要处理此问题:(仅当出现警报时)

driver.get("http://username:password@google.com/")
相关问题