【问题标题】:Problems with setting up proxy for chrome using selenium 3.8.1使用 selenium 3.8.1 为 chrome 设置代理的问题
【发布时间】:2018-01-23 22:23:23
【问题描述】:

我曾经像下面的代码一样在 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 设置代理的替代方法。

【问题讨论】:

  • 用您看到的错误更新问题。
  • 我告诉过我没有收到任何错误

标签: python google-chrome selenium-webdriver proxy


【解决方案1】:

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

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')

【讨论】:

  • 这个答案可以通过解释问题是什么来改进
  • 我真的不知道问题出在哪里,我假设在新版本的 selenium chrome_options=options 中根本不起作用,所以我没有使用 webdriver.ChromeOptions()来自 selenium.webdriver 的 DesiredCapabilities 和代理
  • 感谢您的解决方案,您真的让我很开心!
【解决方案2】:

试试

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"

【讨论】:

  • 很好的答案,特别提供http=<IP>:<PORT>为我工作
【解决方案3】:

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

driver.get("http://username:password@google.com/")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 2019-01-19
    相关资源
    最近更新 更多