I'm using selenium to automatically download files in csv format from this page:
https://catalog.data.gov/dataset?tags=crime
This is the code I'm using:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", '/home/luis/Desktop/data/')
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")
driver = webdriver.Firefox(firefox_profile=profile)
driver.get(url)
time.sleep(2)
download_button = driver.find_element_by_xpath('//*[@id="content"]/div[2]/div[2]/section[1]/div[2]/ul/li[14]/div/ul/li[1]/a')
download_button.click()
Here the download folder is set:
profile.set_preference("browser.download.dir", '/home/luis/Desktop/data/')
How can I select the name with which the file is saved?
Can be the name defined at the moment of the download?
I meant something like this:
For name in names:
download_button = driver.find_element_by_xpath('//*[@id="content"]/div[2]/div[2]/section[1]/div[2]/ul/li[14]/div/ul/li[{}]/a'.format(name))
download_button.click()
save_file_as(name)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…