简体   繁体   English

使用无头选项添加扩展 selenium python

[英]add extension with option headless selenium python

Hi i'd like to add the extension i don't care about cookies on selenium but i have this error: selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://fihnjjcciajhdojfnbdddfaoknhalnja/_generated_background_page.html嗨,我想添加扩展i don't care about cookies上的 cookies 但我有这个错误: selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://fihnjjcciajhdojfnbdddfaoknhalnja/_generated_background_page.html

someone can help me?有人可以帮助我吗? Thanks谢谢

        self.service = Service(self.path)
        self.chrome_options = webdriver.ChromeOptions()
        self.chrome_options.add_extension("tools/I-don-t-care-about-cookies.crx")
        self.chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
        self.chrome_options.add_argument('--headless')
        self.chrome_options.add_argument('--disable-gpu')
        self.chrome_options.add_argument('--no-sandbox')
        self.driver = webdriver.Chrome(service=self.service,options=self.chrome_options)```

First, install the extension in your Chrome browser, and check if it works.首先,在您的 Chrome 浏览器中安装扩展程序,并检查它是否有效。 Then chek the correct extension location.然后检查正确的扩展位置。 Then you can install it when launching the chromedriver like so:然后您可以在启动 chromedriver 时安装它,如下所示:

chrome_options = Options()
[...]
chrome_options.add_argument('--load-extension=/home/user/.config/chromium/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.43.0_0')

Selenium documentation can be found at https://www.selenium.dev/documentation/ Selenium 文档位于https://www.selenium.dev/documentation/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM