禁用firefox保存为dialog-selenium [英] Disable firefox save as dialog-selenium

查看:232
本文介绍了禁用firefox保存为dialog-selenium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网站用硒刮,每当我尝试下载我的文件的Firefox下载/保存为文件弹出,但是,即使我应用 profile.set_preference('browser.helperApps.neverAsk.saveToDisk ',application / csv),它仍然无法正常工作,我试过每一个.csv相关的MIME,但不起作用,是否可以点击另存为单选按钮,然后单击对话框上的 ok 或完全禁用它。

解决方案

你应该做两件事,首先设置这三个偏好如下(这是在Java中,但我想你设法翻译那对python: - ):

$ p $ profile.setPreference(browser.download.dir,c:/ yourDownloadDir) ;
profile.setPreference(browser.download.folderList,2);
profile.setPreference(browser.helperApps.neverAsk.saveToDisk,application / csv,text / csv);

其次,您应该确保下载文件具有所需的MIME类型。要做到这一点,你可以使用网络开发工具和检查下载。



编辑:



出来MIME类型打开Chrome,按 Ctrl + Shift + I (Mac OS上的Cmd + Alt +标签并点击你的下载链接。你应该看到这样的内容:




I am web scraping with selenium and whenever i try to download i file the firefox download/save as file pops up however, even If i apply profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "application/csv"), it still doesnt work, I have tried everyt .csv related MIME but doesn't work, is it possible to either click save as radio button and then click ok on the dialog or disable it entirely.

解决方案

you should do two things, first set these three preferences as follows (this is in Java but I guess you manage to translate that to python :-):

profile.setPreference("browser.download.dir", "c:/yourDownloadDir");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/csv, text/csv");

secondly, you should make sure the download file has the desired mime type. To do that, you can use the web developer tools and inspect the download.

EDIT:

To find out the MIME type open Chrome, press Ctrl+Shift+I (Cmd+Alt+I on Mac OS) change to the 'Network' tab and click your download link. You should see something like this:

这篇关于禁用firefox保存为dialog-selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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