Я пытаюсь запустить прокси с логином и паролем в chrome в безголовом режиме таким образом:
try:
try:
path = os.path.dirname(os.path.abspath(__file__))
os.remove(f'{path}\\Chrome\\Application\\89.0.4389.90\\Extensions\\proxy_auth_plugin.zip')
except:
pass
ZipFile(f'{path}\\Chrome\\Application\\89.0.4389.90\\Extensions\\proxy_auth_plugin.zip', 'w')
def proxy_chrome(PROXY_HOST,PROXY_PORT,PROXY_USER,PROXY_PASS):
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = """
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%(host)s",
port: parseInt(%(port)d)
},
bypassList: ["foobar.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%(user)s",
password: "%(pass)s"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
""" % {
"host": PROXY_HOST,
"port": int(PROXY_PORT),
"user": PROXY_USER,
"pass": PROXY_PASS,
}
path = os.path.dirname(os.path.abspath(__file__))
pluginfile = f'{path}\\Chrome\\Application\\89.0.4389.90\\Extensions\\proxy_auth_plugin.zip'
with zipfile.ZipFile(pluginfile, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
path = os.path.dirname(os.path.abspath(__file__))
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument("--disable-application-cache")
chrome_options.add_argument("start-maximized")
chrome_options.headless = True
chrome_options.binary_location = os.path.join(path, r'Chrome\Application\chrome.exe')
chrome_options.add_extension(pluginfile)
driver = webdriver.Chrome(executable_path=os.path.join(path, 'chromedriver.exe'),chrome_options=chrome_options)
return driver
PROXY_HOST'***'
PROXY_PORT='***'
PROXY_USER='***'
PROXY_PASS='***'
driver=proxy_chrome(PROXY_HOST,PROXY_PORT,PROXY_USER,PROXY_PASS)
except Exception as x:
print(repr(x))
print('Что то не так с прокси')
raise Exception('Что то не так с прокси')
но получаю ошибку:
unknown error: failed to wait for extension background page to load: chrome-extension://icopbmefnonpflniijpjjponhlkcmiao/_generated_background_page.html
from unknown error: page could not be found: chrome-extension://icopbmefnonpflniijpjjponhlkcmiao/_generated_background_page.html
Буду благодарен любой помощи
Спасибо