How can I get rid of this keep/discard
notification while downloading files via python selenium chromedriver?
I've tried with the following but could not succeed:
chromeOptions = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chromeOptions.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)
EDIT: It seems I've found out another website having such ".eml" file which throws the same notification upon clicking on that link ending with .eml
.
Example website link
I'm trying with the below approach:
from selenium import webdriver
url = "https://www.online-convert.com/file-format/eml"
dirf = r"C:\Users\WCS\Desktop\emlfolder"
def download_file(link):
driver.get(link)
driver.find_element_by_css_selector("a[href$='example.eml']").click()
if __name__ == '__main__':
chromeOptions = webdriver.ChromeOptions()
prefs = {'download.default_directory' : dirf}
chromeOptions.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)
download_file(url)
The notification exactly looks like the image below:
Btw, I'm initiating click on that link to download only because the site I was experimenting with doesn't have any true url connected to that ".eml" files to navigate. Turn out that navigating to that ".eml" link lead to the same notification as well.
You need to specify the file extension you want to download
prefs = {
'download.default_directory': dirf,
'download.prompt_for_download': False,
'download.extensions_to_open': 'eml',
'safebrowsing.enabled': False
}
options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=options)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With