Hi to all, I have been trying to download a file from a webpage by clicking on the download button. I am using Selenium and the code runs without errors. It even downloads a screenshot and stores it at the desired folder. However, the file that I want to download does not appear anywhere. Here is the code:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
downloadpath = "/home/foo/.virtualenvs/bar/static/UPLOAD_FOLDER"
chrome_options = webdriver.ChromeOptions()
chrome_options.w3c = True
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--safebrowsing-disable-download-protection")
chrome_options.add_argument("window-size=1440,900")
chrome_options.add_experimental_option("prefs", {
"download.default_directory": downloadpath,
"directory_upgrade": True,
"extensions_to_open": "",
"download.prompt_for_download": False,
"download.safebrowsing.enabled": True
})
chrome_options.add_experimental_option('w3c', True)
browser = webdriver.Chrome(options=chrome_options)
try:
browser.get('https://data.buenosaires.gob.ar/dataset/sistema-unico-atencion-ciudadana')
print(browser.title)
node = WebDriverWait(browser, 20).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "btn")))
for n in node:
print(n.text)
node[-1].click()
browser.get_screenshot_as_file("/home/foo/.virtualenvs/bar/static/UPLOAD_FOLDER/download_screenshot.png")
time.sleep(50)
except Exception as e:
s = str(e)
s = "{} - Algo anda mal - linea 46".format(s)
print(s)
finally:
browser.quit()
[edit by admin: formatting]