使用Python中的Selenium下载文件

使用Python中的Selenium下载文件,python,selenium,firefox,web-scraping,Python,Selenium,Firefox,Web Scraping,我正在尝试从一个包含阿根廷代表投票的公共网站自动下载excel文件。例如,从以下页面: 我正在通过Python使用firefox webdriver和Selenium。 当我尝试单击图像中的按钮时: 我收到以下信息: selenium.common.exceptions.Element ClickInterceptedException:消息: 元素在点(229480)处不可单击,因为另一个 元素掩盖了它 如果我试图通过driver.execute_脚本('javascript:exportE

我正在尝试从一个包含阿根廷代表投票的公共网站自动下载excel文件。例如,从以下页面:

我正在通过Python使用firefox webdriver和Selenium。 当我尝试单击图像中的按钮时:

我收到以下信息:

selenium.common.exceptions.Element ClickInterceptedException:消息: 元素在点(229480)处不可单击,因为另一个 元素掩盖了它

如果我试图通过
driver.execute_脚本('javascript:exportExcel();')
什么也没发生


有什么方法可以让它工作吗?

您需要单击下载按钮,然后使用Autoit或其他ui自动机创建自动下载对话框。

最后,我可以完成它。我用的是日常生活。但是必须更改
选项。设置首选项(“browser.helperApps.neverAsk.saveToDisk”,“application/octet stream,application/vnd.ms excel”)
指令由
选项。设置首选项(“browser.helperApps.neverAsk.saveToDisk”,“application/vnd.openxmlformats of cedocument.spreadsheetml.sheet”)

例如:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.set_preference("browser.download.folderList",2)
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.download.dir","/data")
options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

with webdriver.Firefox(options=options) as driver:
    
    driver.get('https://votaciones.hcdn.gob.ar/votacion/4108')
    driver.execute_script('javascript:exportExcel();')