【问题标题】:Socks5 Proxy Configuration in Selenium Firefox driverSelenium Firefox 驱动程序中的 Socks5 代理配置
【发布时间】:2021-07-03 11:37:19
【问题描述】:

我正在尝试通过这种方式在 selenium 中使用代理:

firefox_options.add_argument('--proxy-server=socks5://' + 'username:pwd:addr@ipvanish.com:port')

我正在使用 ipvanish 的代理 有一些我不知道放在哪里的主机名 有人可以告诉我如何在不使用任何扩展的情况下正确配置代理吗?我搜索并找到了一些方法,虽然我还无法理解该方法,所以如果您能明确解释一下,我将不胜感激。

【问题讨论】:

    标签: python selenium selenium-webdriver proxy


    【解决方案1】:

    如果您使用user:pass 身份验证,则必须使用Proxy Auto Auth 扩展名进行身份验证。

    使用 Crx downloader 扩展名将扩展名下载为 zip 文件。

    然后您可以在 selenium 浏览器中加载代理自动身份验证扩展。

    对于 Python

    import os
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    executable_path = "path_to_webdriver"
    os.environ["webdriver.chrome.driver"] = executable_path
    chrome_options = Options()
    chrome_options.add_extension('path_to_extension')
    chrome_options.add_argument('--proxy-server=socks5://' + 'addr@ipvanish.com:port')
    driver=webdriver.Chrome(executable_path=executable_path,chrome_options=chrome_options)
    driver.get("http://stackoverflow.com")
    driver.quit()
    

    扩展名的路径是包含扩展名的manifest.json文件的文件夹的路径 然后你可以简单地使用下面的代码验证代理的代码

    driver.Navigate().GoToUrl(@"chrome-extension://extensionName/options.html");
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("login"))).Clear();
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("login"))).SendKeys("username");
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("password"))).Clear();
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("password"))).SendKeys("pwd");
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("retry"))).Clear();
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("retry"))).SendKeys("5");
    wait.Until(ExpectedConditions.ElementIsVisible(By.Id("save"))).Click();
    

    这段C#代码希望你能翻译成python。

    此外,您还可以提取下载的扩展 Zip 文件并从文件夹中将其加载到浏览器中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 2021-05-30
      • 2020-09-04
      • 2014-11-05
      • 2013-04-25
      • 1970-01-01
      相关资源
      最近更新 更多