在chromedriver中禁用PDF Viewer插件

发布于 2021-01-29 15:00:31

我正在尝试在Blackboard环境中批量下载很多文件(在世界各地的大学/学校中经常使用)。我能够检索文件所在的链接,但是一个市长问题:

当文件是.pdf文件时,它会显示在新的浏览器选项卡中,而不是被下载。例如,使用click()下载.xlsx文件就可以了。

我可以更改驱动程序设置来更改此行为吗?如何?

编辑
我更新了这个问题以回应Ari的回答。现在,它包含有关实际插件的更多信息。也许可以用来识别必须禁用的插件。

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
关注者
0
被浏览
119
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    阿里的答案几乎可以正常工作。我只需要将插件的名称封装到一个列表中:

    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)
    

    现在下载工作正常!



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看