Python Selenium Chrome disable prompt for Trying to download multiple files

2024/10/6 1:40:02

I am currently running a Python automator which needs to download multiple files within the same session using Selenium Chromedriver.

The problem is that when the browser attempts to download the second file and read it, the browser will not download until the "Allow" button has been clicked.

I have researched the ChromeOptions part of Selenium to do with disabling it, but many of the answers were in Java, or even other browsers.

To summarise, how do you disable the prompt for allowing multiple file downloads?

Answer

Did you try passing the according preference to webdriver?

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Optionschromedriver = "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()
https://en.xdnf.cn/q/70423.html

Related Q&A

Label outliers in a boxplot - Python

I am analysing extreme weather events. My Dataframe is called df and looks like this:| Date | Qm | |------------|--------------| | 1993-01-…

Matplotlib how to draw vertical line between two Y points

I have 2 y points for each x points. I can draw the plot with this code:import matplotlib.pyplot as pltx = [0, 2, 4, 6] y = [(1, 5), (1, 3), (2, 4), (2, 7)]plt.plot(x, [i for (i,j) in y], rs, markersiz…

Cythonizing fails because of unknown type name uint64_t

This may be a newbie problem. I cant cythonize a simple helloworld.pyx tutorial script while the exact same code works on linux:print("hello world")Here is the setup.py script: from distutils…

How to save changes in read-only Jupyter Notebook

I have opened a python Jupyter notebook but did not notice that it was in read-only, Not Trusted mode. How to save my changes now?Things that I have tried and did not help:File -> Make a Copy File …

How can I invoke an SQLAlchemy query with limit of 1?

I have code like this:thing = thing.query.filter_by(id=thing_id).limit(1).all()[0]all()[0] feels a bit messy and redundant in the limit(1) case. Is there a more terse (and/or otherwise optimal) way to …

How to correctly create Python feature branch releases in development? (pip and PEP-440)

I develop a Python library using Gitflow development principle and have a CI stage for unit testing and package upload to a (private) PyPI. I want to consume the uploaded package for testing purposes b…

How do I replace NA with NaN in a Pandas DataFrame?

Some columns in my DataFrame have instances of <NA> which are of type pandas._libs.missing.NAType. Id like to replace them with NaN using np.nan. I have seen questions where the instances of <…

concatenation of two or more base64 strings in python

Im tring to concatenate two strings encoded to base64 but it doesnt really work, just prints the first string in concatanation:q = base64.b64encode("StringA") print q # prints an encoded stri…

How to find shared library used by a python module?

I am debugging a python program based on pygtk and I want to make sure that the program is using the right shared library.pygtk is a GTK+ wrapper for python. I have already compiled GTK+ using jhbuild …

Python groupby doesnt work as expected [duplicate]

This question already has answers here:itertools.groupby() not grouping correctly(3 answers)Closed 5 years ago.I am trying to read an excel spreadsheet that contains some columns in following format:co…