Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python selenium chromedirver( headerless) use proxies( IPV6 ) with Authentication

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.

like image 340
Aditya Mishra Avatar asked Nov 30 '18 10:11

Aditya Mishra


1 Answers

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)
like image 160
ewwink Avatar answered Nov 02 '22 07:11

ewwink