Search code examples
pythonpython-3.xweb-scrapingrpa

How to save the file in the current disk when downloading using python?


chrome_options = webdriver.ChromeOptions()

# Set preferences
prefsNotifications = {"profile.default_content_setting_values.notifications" : 2} 
prefsPopups = {"profile.default_content_settings.popups": 0}
prefsDownload = {"download.default_directory": CurDir}
prefsSafe = {'safebrowsing.enabled': 'false'}
chrome_options.add_experimental_option("prefs", prefsNotifications)
chrome_options.add_experimental_option("prefs", prefsPopups)
chrome_options.add_experimental_option("prefs", prefsDownload)
chrome_options.add_experimental_option("prefs", prefsSafe)

driver = webdriver.Chrome(CurDir+"\\chromedriver.exe", chrome_options=chrome_options)
driver.maximize_window()  
return driver

Lines 5 and 9, notify: The file is not safe when downloading. I removed those two lines. It can not save in my wanted disk.

How can I solve this issue?


Solution

  • def OpenBrowser():
        chromeOptions = webdriver.ChromeOptions()
        prefs = {"download.default_directory" : CurDir,"safebrowsing.enabled": "false","profile.default_content_setting_values.notifications" : 2, "profile.default_content_settings.popups": 0}
        chromeOptions.add_experimental_option("prefs",prefs)
        driver = webdriver.Chrome(executable_path = CurDir+"\\chromedriver.exe", chrome_options = chromeOptions)
        driver.maximize_window()
        return driver
    

    Function open chromedriver.exe by selenium with no notifications, warnings or popups. 1 prefs.