Python selenium chromedirver( headerless) use proxies( IPV6 ) with Authentication
Asked Answered
D

2

8

I have IPV6 proxies which require Username and Password to work, Is there any way I can use these proxies in ChromeDriver ( Headerless ) with username and password.

proxies in format - ip_address:port username:password

if not then is there any way I can change my system ipv6 address using these proxies so ChromeDriver by default takes system IP address.

Dicast answered 30/11, 2018 at 10:14 Comment(0)
O
6

you can create simple extension to set proxy and handle the authorization

manifest.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 edit 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']
);

add both file to .zip archive then in your python script

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

driver = webdriver.Chrome(options=options)
Oriane answered 8/12, 2018 at 9:10 Comment(0)
A
0

Solition with extention not work for headless mode. An error raised:

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
Ague answered 21/9, 2019 at 20:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.