問題描述
我在啟用 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 中永久安裝擴展程序
這篇關于如何使用 python 在 selenium 的 chrome 驅動程序中加載擴展的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!