failed to wait for extension background page to load
代码如下:
from selenium import webdriver
import string
import zipfile
proxyHost = "http-dyn.abuyun.com"
proxyPort = "9020"
proxyUsername = "H5IM8T3H288W241D"
proxyPassword = "5C4448B395A6FF16"
def create_proxy_auth_extension(proxy_host, proxy_port,
proxy_username, proxy_password,
scheme='http', plugin_path=None):
if plugin_path is None:
plugin_path = r'./{}_{}@http-dyn.abuyun.com_9020.zip'.format(proxy_username, proxy_password)
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Abuyun Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = string.Template(
"""
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "${scheme}",
host: "${host}",
port: parseInt(${port})
},
bypassList: ["foobar.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "${username}",
password: "${password}"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
"""
).substitute(
host=proxy_host,
port=proxy_port,
username=proxy_username,
password=proxy_password,
scheme=scheme,
)
with zipfile.ZipFile(plugin_path, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
return plugin_path
def init_driver():
proxy_auth_plugin_path = create_proxy_auth_extension(proxy_host=proxyHost, proxy_port=proxyPort,
proxy_username=proxyUsername, proxy_password=proxyPassword,
scheme='http', plugin_path=None)
options = webdriver.ChromeOptions()
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--hide-scrollbars')
options.add_argument('--headless')
options.add_argument("--test-type")
options.add_argument("--no-first-run")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--no-default-browser-check")
options.add_extension(proxy_auth_plugin_path)
return webdriver.Chrome(options=options)
if name == '__main__':
driver = init_driver()
url = 'http://www.baidu.com'
driver.get(url)
print(driver.page_source)
异常如下:
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://kidcehangkjhnmdccclekheeighbkegc/_generated_background_page.html
from unknown error: page could not be found: chrome-extension://kidcehangkjhnmdccclekheeighbkegc/_generated_background_page.html
(Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.11.6 x86_64)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以通过squid进行解决