Win*_*ags 5 python firefox selenium
我selenium在 Python 2.7 中使用这些 Firefox 首选项设置:
ff_profile = webdriver.FirefoxProfile(profile_dir)
ff_profile.set_preference("browser.download.folderList", 2)
ff_profile.set_preference("browser.download.manager.showWhenStarting", False)
ff_profile.set_preference("browser.download.dir", dl_dir)
ff_profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream")
Run Code Online (Sandbox Code Playgroud)
使用 Selenium,我想反复下载相同的文件,并覆盖它,从而保持相同的文件名——无需我确认下载。
通过上面的设置,它会下载不求回报的位置,但所有的下载将与文件名创建副本filename (1).ext,filename (2).ext等在MacOS上。
我猜可能没有设置允许从 Firefox 内部覆盖,以防止意外(?)。
(在这种情况下,我认为解决方案是使用其他 Python 模块处理磁盘上的覆盖;另一个主题)。
这超出了 Selenium 的范围,由操作系统处理。
根据此问题和上一个问题的上下文判断,您事先知道(或可以从链接文本确定)文件名。如果确实如此,在点击“下载”链接之前,请确保删除现有文件:
import os
filename = "All-tradable-ETFs-ETCs-and-ETNs.xlsx" # or extract it dynamically from the link
filepath = os.path.join(dl_dir, filename)
if os.path.exists(filepath):
os.remove(filepath)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2231 次 |
| 最近记录: |