如何使用python在Selenium中的Chrome驱动程序中加载扩展 [英] How to load extension within chrome driver in selenium with python

查看:644
本文介绍了如何使用python在Selenium中的Chrome驱动程序中加载扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有在启用Browserc扩展功能的情况下打开chrome浏览器的尝试都失败了.这是我最后尝试过的-

All my efforts to open chrome browser with Browsec extension enabled are failing. Here is what i tried in last -

# 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")

这导致错误无法从加载扩展名".清单文件丢失或不可读"

This results in error "Failed to load extension from . Manifest files is missing or unreadable"

搜索此错误后,我得到Manifest.json文件应重命名为manifest.json.txt,但是这样做会导致相同的错误.

After search for this error I get that Manifest.json file should be renamed to manifest.json.txt but doing this resulted in same error.

我们将不胜感激任何帮助

Any help will be highly appreciated

推荐答案

要打开具有任何扩展名的chrome浏览器,您需要使用 chrome.options 类,您可以使用以下解决方案:

To open chrome browser with any extension you need to use the add_extension() method through an instance of chrome.options class and you can use the following solution :

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()


参考文献

您可以在以下位置找到相关文档:


References

You can find the relevant documentation in:

您可以在以下位置找到一些相关的讨论:

You can find a couple of relevant discussions in:

  • [Python] How to install Chrome Extension using Selenium & Python
  • [Java] How to install extension permanently in geckodriver

这篇关于如何使用python在Selenium中的Chrome驱动程序中加载扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆