Python硒色服务器(无头)使用带有身份验证的代理(IPV6)



我有IPV6代理,需要用户名和密码才能工作,有没有什么方法可以让我在ChromeDriver(无标题(中使用这些代理,并使用用户名和密码。

格式中的代理-ip_address:端口用户名:密码

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

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

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编辑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)

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

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

最新更新