Disabling PDF Viewer plugin in chromedriver

不羁的心 提交于 2019-12-20 04:13:29

问题


I'm trying to batch-download a lot of files within the BlackBoard environment (used a lot on universities/schools around the world). I am able to retrieve the links where the files are but one mayor issue:

When the file is a .pdf-file, it is shown in a new browser-tab in stead of being downloaded. For e.g. .xlsx-files downloading with a click() works just fine..

Can I change the driversettings to change this behaviour? And how?

Edit
I updated the question in reaction to Ari's answer. It's now including more info on the actual plugin. Maybe that's usable to identify the plugin which has to be disabled..

Chrome PDF Viewer (2 files)

   Name:            Chrome PDF Viewer
       Version: 
       Location:    chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/
       Type:        BROWSER PLUGIN
                    Disable
       MIME types:  MIME type        Description     File extensions
                    application/pdf                  .pdf

   Name:            Chrome PDF Viewer
       Description: Portable Document Format
       Version: 
       Location:    internal-pdf-viewer
       Type:        PPAPI (out-of-process)
                    Disable
       MIME types:  MIME type        Description    File extensions
                    application/x-google-chrome-pdf Portable Document Format    
                    .pdf   

回答1:


Chrome 57 change the setting... use this to disable Chrome PDF viewer:

//To disable PDF viewer plugins with Chrome 57
chromePrefs.put("plugins.always_open_pdf_externally", true);



回答2:


Ari's answer was almost working properly. I only needed to encapsulate the plugin's name into a list:

chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]} # Here should be a list
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

The downloading now works just fine!




回答3:


Can you set the plugin to be disable as a preference?

chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : "Chrome PDF Viewer"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

See "setting Chrome preferences w/ Selenium Webdriver in Python" and "How to disable Chrome Plugins in Selenium WebDriver using Java".



来源:https://stackoverflow.com/questions/41877155/disabling-pdf-viewer-plugin-in-chromedriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!