禁用chrome下载多个文件确认 [英] Disable chrome download multiple files confirmation

查看:2488
本文介绍了禁用chrome下载多个文件确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ruby watir-webdriver开发了一个抓取工具,从页面下载一些文件。我的问题是,当我点击下载第二个文件时,Chrome会在顶部打开一个栏,要求确认我正在从该网站下载多个文件。



由webdriver使用,我无法确认下载。无论如何避免这种确认?我在考虑是否有任何配置来避免它,或者是否有扩展来做到这一点,或者即使我可以点击webdriver的确认。



谢谢

p>

解决方案

我使用的是Chrome 49,其他解决方案都不适用于我。
经过一番研究后,我发现了一个工作解决方案:
$ b $ pre $ ChromeDriver createChromeDriverWithDownloadFolder(字符串文件夹){
Map<字符串,对象> chromePrefs = new HashMap< String,Object>();
chromePrefs.put(profile.default_content_settings.popups,0);
chromePrefs.put(download.default_directory,文件夹);
chromePrefs.put(profile.content_settings.exceptions.automatic_downloads。*。setting,1);
chromePrefs.put(download.prompt_for_download,false);

ChromeOptions选项=新ChromeOptions();
options.setExperimentalOption(prefs,chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
cap.setCapability(ChromeOptions.CAPABILITY,options);
返回新的ChromeDriver(cap);
}

好像这些设置不断变化。因此,下面是我为我的设置找到了正确的解决方案:


  1. 打开Chrome并转至chrome:// version /以查找路径您的个人资料
  2. 默认/首选项是一个名为首选项的json文件。打开它并搜索 automatic_downloads
    在我的例子中,文件的有趣部分看起来像这样:
    $ b

    ...profile:{
    avatar_bubble_tutorial_shown:1,
    avatar_index:0,
    content_settings:{
    clear_on_exit_migrated:true,
    exceptions:{
    app_banner:{},
    auto_select_certificate:{},
    automatic_downloads:{
    [。] localhost:63342,:{
    setting:1
    },...


  3. 由此我可以推导出正确的设置是 chromePrefs.put(profile .content_settings.exceptions.automatic_downloads。*。setting,1);



I developed a crawler with ruby watir-webdriver that downloads some files from a page. My problem is that when I click to download the second file, Chrome opens a bar in the top asking for confirmation that I am downloading multiple files from this website.

Once this is used by webdriver, I cannot confirm the download. Is there anyway to avoid this confirmation? I am thinking if is there any configuration to avoid it or if is there an extension to do this or even if I can click on the confirmation with webdriver.

thanks

解决方案

I'm using Chrome 49 and none of the other solutions worked for me. After some research I found a working solution:

ChromeDriver createChromeDriverWithDownloadFolder(String folder) {
    Map<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", folder);
    chromePrefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1 );
    chromePrefs.put("download.prompt_for_download", false);

    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(cap);
}

It seems as if these settings are constantly changing. Therefore, here's how I found the right solution for my setup:

  1. Open Chrome and go to chrome://version/ to find the path of your profile
  2. In Default/Preferences is a json file called Preferences. Open it and search for automatic_downloads. In my case the interesting part of the file looked like this:

    ..."profile": { "avatar_bubble_tutorial_shown": 1, "avatar_index": 0, "content_settings": { "clear_on_exit_migrated": true, "exceptions": { "app_banner": {}, "auto_select_certificate": {}, "automatic_downloads": { "[.]localhost:63342,": { "setting": 1 },...

  3. From that I could derive that the right setting would be chromePrefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1 );

这篇关于禁用chrome下载多个文件确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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