Firefox + Selenium WebDriver and download a csv file automatically(Firefox + Selenium WebDriver 并自动下载 csv 文件)
问题描述
我对 Selenium WebDriver 和 Firefox 有疑问.我想下载 csv 文件而不在对话框窗口中确认,我有这样的代码:
I have problem with Selenium WebDriver and Firefox. I want to download csv file without confirmation in dialog window and I have code like this:
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.dir", download_dir)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")
但它似乎不起作用.我尝试了许多与 browser.helperApps.neverAsk.saveToDisk
but it seems not working. I tried many combination with browser.helperApps.neverAsk.saveToDisk
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/csv,text/plan,text/comma-separated-values")
或
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/csv")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/plain")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/comma-separated-values")
但没有区别,Firefox 不会自动下载.我该如何解决?
but there's no difference and Firefox won't download automaticly. How can I fix it?
推荐答案
有时内容类型不符合您的预期使用 HttpFox Firefox 插件(或类似插件)查找文件的真实内容类型并在您的代码中使用它
Sometime the content type is not as you'd expect Use HttpFox Firefox plugin (or similar) to find the real content type of the file and use it in your code
顺便说一句,对我来说内容类型是
BTW, For me the content type was
fp.set_preference("browser.helperApps.neverAsk.openFile", "application/octet-stream");
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
这篇关于Firefox + Selenium WebDriver 并自动下载 csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Firefox + Selenium WebDriver 并自动下载 csv 文件
基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01