The Python Oracle

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

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping

--

Chapters
00:00 Can'T Get Rid Of &Quot;Keep/Discard&Quot; Notification While Downloading &Quot;.Eml&Quot; Files
01:08 Answer 1 Score 2
01:21 Accepted Answer Score 6
01:35 Answer 3 Score 0
02:40 Answer 4 Score 0
03:10 Thank you

--

Full question
https://stackoverflow.com/questions/5449...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #python3x #selenium #webscraping #seleniumchromedriver

#avk47



ACCEPTED ANSWER

Score 6


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)



ANSWER 2

Score 2


That's popup related to safe browsing. try

  chromeOptions = webdriver.ChromeOptions()
  prefs = {'safebrowsing.enabled': 'false'}
  chromeOptions.add_experimental_option("prefs", prefs)
  driver = webdriver.Chrome(chrome_options=chromeOptions)



ANSWER 3

Score 0


According to this: How to disable 'This type of file can harm your computer' pop up you will need multiple options:

The accepted answer stopped working after a recent update of Chrome. Now you need to use the --safebrowsing-disable-extension-blacklist and --safebrowsing-disable-download-protection command-line switches.

But whenever someone at Google has second thoughts about security issues related to an option, they will modify the behaviour in the next version of Chrome. I am using Chrome 72 and the above mentioned options do not disable the notification anymore.

The short version: Do not try to disable security measures. Malware authors are trained to do that and any good browser developer seems to think "better safe than sorry".

If you really need just a download solution, you can use the requests module and download without chrome:

from selenium import webdriver
import requests

url = "https://www.online-convert.com/file-format/eml"

dirf = r"C:\Users\WCS\Desktop\emlfolder"

def download_file(link):
    driver.get(link)
    linkElement = driver.find_element_by_css_selector("a[href$='example.eml']")
    r = requests.get(linkElement.get_attribute('href'))
    file = open("C:\Users\WCS\Desktop\emlfolder\example.eml", 'wb')
    file.write(r.content)
    file.close()

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)
    driver.quit()



ANSWER 4

Score 0


You could try and add the website to the trusted sites list of chrome, If i understand your code, it uses your install of chrome, which would mean that if you were to change settings in chrome, the python module would use them.

Chrome

Click the 3 horizontal lines icon on the far right of the Address bar.

Click on Settings, scroll to the bottom and click the Show Advanced Settings link.

Click on Change proxy settings.

Click the Security tab > Trusted Sites icon, then click Sites.

Enter the URL of your Trusted Site, then click Add.

Click Close > OK.