Python Selenium Chrome 禁用提示 "Trying to download multiple files"

标签 python selenium selenium-chromedriver chrome-options

我目前正在运行一个 Python 自动程序,它需要使用 Selenium Chromedriver 在同一 session 中下载多个文件。

问题是当浏览器尝试下载第二个文件并读取它时,浏览器将不会下载,直到单击“允许”按钮。

我研究了 Selenium 的 ChromeOptions 部分以禁用它,但很多答案都是用 Java 甚至其他浏览器。

总结,如何禁用允许多个文件下载的提示?

最佳答案

您是否尝试将相应的首选项传递给 webdriver

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chromedriver = "path/to/chromedriver"

os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = Options()

# this is the preference we're passing
prefs = {'profile.default_content_setting_values.automatic_downloads': 1}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

# just downloading some files...
for _ in range(5):
    driver.get("http://code.jquery.com/jquery-1.11.3.min.map")

driver.quit()

关于Python Selenium Chrome 禁用提示 "Trying to download multiple files",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31430532/

相关文章:

python - Selenium : WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

java - Element.getattribute ("Value") 和 gettext() 不适用于使用 Java 的 selenium webdriver

python - Pygame 在 Windows 10 上使用 pip install pygame 失败

python - 是否可以让这个 Xpath 变得更短?

python - Pandas:如何用 nan 维护列的类型?

java - 无法在Java中使用selenium webdriver自动登录Gmail

selenium - 如何关闭 Selenium Grid2 服务器?

selenium - 是否可以自动打开 Google Chrome devtools?

Python Regex\pL 匹配问题

python - WxPython 将选择转换为数值 TypeError