python - 允许 Firefox 使用 Selenium 自动下载文件。这可以用 PhantomJS 完成吗?

标签 python excel selenium

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)

fp.set_preference("browser.helperApps.alwaysAsk.force", False)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.manager.useWindow", False);
fp.set_preference("browser.download.manager.alertOnEXEOpen", False)

fp.set_preference("browser.download.folderList", 2);
fp.set_preference("browser.download.dir", '/home/ubuntu');
fp.set_preference("browser.download.manager.alertOnEXEOpen", False);
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel, application/force-download,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msword, application/XLS;text/csv, application/XLSX;text/csv, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
fp.set_preference("browser.download.manager.showWhenStarting", False);
fp.set_preference("browser.download.manager.focusWhenStarting", False);  
fp.set_preference("browser.download.useDownloadDir", True);
fp.set_preference("browser.helperApps.alwaysAsk.force", False);
fp.set_preference("browser.download.manager.alertOnEXEOpen", False);
fp.set_preference("browser.download.manager.closeWhenDone", True);
fp.set_preference("browser.download.manager.showAlertOnComplete", False);
fp.set_preference("browser.download.manager.useWindow", False);
fp.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False);
fp.set_preference("pdfjs.disabled", True);
driver = webdriver.Firefox(firefox_profile=fp)

这是我使用 Selenium 保存文件的代码。它适用于其他文件,但不适用于 Excel。如您所见,在此处输入代码,我已经包含了一些 Excel 文件格式,但这些也不起作用。

另外,PhantomJs有这个能力吗?我进行了搜索,但没有找到任何可以证实 PhantomJs 具有此功能的内容。

感谢您的协助。

最佳答案

感谢您的回复。

我尝试使用 text/csv,但也没有用。我最终做的是安装监控网络流量和事件的 httpFox。使用 httpFox,我能够放大确切的 MIME-TYPE,即: fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/msexcel, text/csv")

我尝试了其他几个我在互联网上找到的 Excel MIME-TYPES,但除了我使用的那个之外,它们都不起作用。

T

关于python - 允许 Firefox 使用 Selenium 自动下载文件。这可以用 PhantomJS 完成吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34091113/

相关文章:

带有数千个逗号和空格的 python f-string 整数

VBA 错误处理不适用于 Excel 2016 中的一位用户

excel - 在影响整个工作表的一列中搜索/替换

python - 使用 Python 或 R 读取动态网页 html

java - 使用 selenium web 驱动程序可以在单个单元格中打印多个值

python - XPath : is it possible? (Python) 中的累加器

python - 使用 Nelder-Mead 最小化非凸函数

python - Python 中有哪些线程安全的数据持久化对象用于数据持久化?

python - 使用TastyPie进行用户注册。如何处理认证?

excel - 倒计时无法取消