python - 如何使用python在selenium中的chrome驱动程序中加载扩展

标签 python selenium google-chrome google-chrome-extension selenium-chromedriver

我在启用 Browsec 扩展的情况下打开 chrome 浏览器的所有努力都失败了。这是我最后尝试过的 -

# Configure the necessary command-line option.
options = webdriver.ChromeOptions()
options.add_argument(r'--load- 
extension=C:\Users\lap0042\AppData\Local\Google\Chrome\User 
Data\Default\Extensions\omghfjlpggmjjaagoclmmobgdodcjboh')

# Initalize the driver with the appropriate options.
driver = webdriver.Chrome(chrome_options=options)

driver.get("http://stackoverflow.com")
这会导致错误“无法从 . 加载扩展名。 list 文件丢失或不可读”
搜索此错误后,我发现应该将 Manifest.json 文件重命名为 manifest.json.txt,但这样做会导致相同的错误。
任何帮助将不胜感激
enter image description here

最佳答案

要使用任何扩展程序打开 Chrome 浏览器,您需要使用 add_extension() 方法通过 chrome.options 的实例类,您可以使用以下解决方案:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_extension(r'C:\path\to\extension.crx')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

引用

您可以在以下位置找到相关文档:
  • ChromeDriver - WebDriver for Chrome .

  • 您可以在以下位置找到一些相关讨论:
  • [Python] How to install Chrome Extension using Selenium & Python
  • [Java] How to install extension permanently in geckodriver
  • 关于python - 如何使用python在selenium中的chrome驱动程序中加载扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50443955/

    相关文章:

    python - 使顶级窗口跟随根 Tk 窗口

    python - 对未知秩的张量应用函数(平均倒数秩)

    python - 我将如何获得 : in a string Python 之前的所有内容

    html - XPath//*[text()]没有选择我想要的文本

    javascript - Selenium 测试 : webdriver. 多次等待调用 promise

    javascript - 在 Chrome 中禁用 'Use Password for' 自动完成

    python - 混淆结果与 python 中的逻辑回归

    java - 如何将 Selenium Testng (java) 与 Testrail 测试用例集成

    angular - Chrome 不在 CrossSide 上发送原始标题

    eclipse:添加Chrome扩展库