【问题标题】:Python selenium chromedirver( headerless) use proxies( IPV6 ) with AuthenticationPython selenium chromedirver(无头)使用代理(IPV6)和身份验证
【发布时间】:2023-03-26 17:11:01
【问题描述】:

我有需要用户名和密码才能工作的 IPV6 代理, 有什么方法可以在 ChromeDriver ( Headerless ) 中使用这些代理和用户名和密码。

代理格式 - ip_address:port 用户名:密码

如果没有,那么有什么方法可以使用这些代理更改我的系统 ipv6 地址,因此 ChromeDriver 默认采用系统 IP 地址。

【问题讨论】:

    标签: python selenium proxy selenium-chromedriver proxies


    【解决方案1】:

    您可以创建简单的扩展来设置代理和处理授权

    ma​​nifest.json

    {
        "manifest_version": 2,
        "name": "Chrome Proxy Auth",
        "version": "1.0.0",
        "permissions": [
            "proxy",
            "tabs",
            "unlimitedStorage",
            "storage",
            "<all_urls>",
            "webRequest",
            "webRequestBlocking"
        ],
        "background": {
            "scripts": ["background.js"]
        }
    }
    

    background.js 编辑host, port, username, password

    var config = {
      mode: "fixed_servers",
      rules: {
        singleProxy: {
          host: "XXX.XXX.XXX.XXX",
          port: parseInt(8888)
        }
      }
    };
    
    chrome.proxy.settings.set({
      value: config,
      scope: "regular"
    }, function() {});
    
    function callbackFunc(details) {
      return {
        authCredentials: {
          username: "............",
          password: "............"
        }
      };
    }
    
    chrome.webRequest.onAuthRequired.addListener(
      callbackFunc, {
        urls: ["<all_urls>"]
      },
      ['blocking']
    );
    

    将这两个文件添加到 .zip 存档,然后在你的 python 脚本中

    options = Options()
    options.add_extension('/path/top/extension.zip')
    
    driver = webdriver.Chrome(options=options)
    

    【讨论】:

      【解决方案2】:

      带扩展的 Solition 不适用于无头模式。 出现错误:

      selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://elfcpkfenboekckgnbhldanchpkcgmfd/_generated_background_page.html
      from unknown error: page could not be found: chrome-extension://elfcpkfenboekckgnbhldanchpkcgmfd/_generated_background_page.html
      

      【讨论】:

        猜你喜欢
        • 2023-04-06
        • 2019-01-05
        • 2013-10-18
        • 2022-06-10
        • 1970-01-01
        • 2021-10-07
        • 2022-08-19
        • 2016-10-13
        • 2014-08-10
        相关资源
        最近更新 更多