如何使用 python 在 selenium 的 chrome 驱动程序中加载扩展
问题描述
我在启用 Browsec 扩展的情况下打开 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:Userslap0042AppDataLocalGoogleChromeUser
DataDefaultExtensionsomghfjlpggmjjaagoclmmobgdodcjboh')
# 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 浏览器,您需要使用 add_extension()
方法通过 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 oextension.crx')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:UtilityBrowserDriverschromedriver.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:
- ChromeDriver - 适用于 Chrome 的 WebDriver.
您可以在以下位置找到一些相关讨论:
You can find a couple of relevant discussions in:
- [Python] 如何使用 Selenium & 安装 Chrome 扩展蟒蛇
- [Java] 如何在 geckodriver 中永久安装扩展程序
相关文章