Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get rid of "keep/discard" notification while downloading ".eml" files

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:

enter image description here

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.

like image 301
robots.txt Avatar asked Mar 05 '23 14:03

robots.txt


1 Answers

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)
like image 82
Guy Avatar answered Apr 27 '23 00:04

Guy