Home>

I want to change the save destination for each loop using Chromedriver.
I'm studying web scraping. At the moment, I can access the page, save the file, and even change the save destination, but when I try to automatically change the save destination for each file using the loop part, a Google error "Failed-" I get a "download error".
When I check the Google settings, it seems that the changes have been made, but for some reason the download does not work.

Corresponding code
from selenium import webdriver
import glob
import os
import pprint
import time
def init_selenium (x):
    ### Set options for Chrome
    options = webdriver.ChromeOptions ()
    options.add_experimental_option ('prefs', {
        'download.default_directory': x,
        'download.prompt_for_download': False,
        'download.directory_upgrade': True,
        'safebrowsing.enabled': True
    })
    driver = webdriver.Chrome (chrome_options = options)
    return driver
files = glob.glob ('C:/Users/koroz/Desktop/fits_make_text/*')
filters = glob.glob ('C: /Users/koroz/Desktop/fits_make_text/{0}/*'.format(files[2][38:]))
texts = glob.glob ('C: /Users/koroz/Desktop/fits_make_text/{0}/{1}/*'.format (files [2] [38:], filters [1] [76:]))
for i in range (len (files)):
    for j in range (len (filters)):
        for k in range (texts):
            download_directory = r "C: /Users/koroz/Desktop/fits_files/{0}/{1}/{2}".format (files [i] [38:], filters [j] [76:], texts [ k] [116: -6])
            driver = init_selenium (download_directory)
            driver.get ("URL")
            element = driver.find_element_by_name ("list")
            element.send_keys ('C: /Users/koroz/Desktop/fits_make_text/ {0}/{1}/{2} _ {3} _ {4} .txt'.format (files [i] [38:], filters [j] [76:], format (files [i] [38:]), texts [k] [116: -6], filters [j] [76:]))
            time.sleep (3)
            button = driver.find_element_by_id ("bulk-submit")
            button.click ()
            time.sleep (10)
            driver.close ();
Error that occurs

There was no error in the execution environment
The error on Google was displayed as "Failed-Download error" when downloading and could not be downloaded.