1

I am working with the following selenium code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options=Options()
options.add_argument("--window-size=1920,1080")

driver=webdriver.Chrome(options=options)
   
driver.get("https://www.ons.gov.uk/")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("Education and childcare")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("Education and childcare")
click_button=driver.find_element_by_xpath('//*[@id="nav-search-submit"]').click()
click_button=driver.find_element_by_xpath('//*[@id="results"]/div[1]/div[2]/div[1]/h3/a/span').click()
click_button=driver.find_element_by_xpath('//*[@id="main"]/div[2]/div[1]/section/div/div[1]/div/div[2]/h3/a/span').click()
click_button=driver.find_element_by_xpath('//*[@id="main"]/div[2]/div/div[1]/div[2]/p[2]/a').click()

The code goes into an open source data website and downloads a report file. At the moment, the file downloads into the downloads folder. How do I adapt this code so that the downloaded file saves inside a specific location. I'd like the file to download in the following location:

C:\Users\David\Desktop\Downloaded_File
  • 2
    Does this answer your question? [Downloading a file at a specified location through python and selenium using Chrome driver](https://stackoverflow.com/questions/35331854/downloading-a-file-at-a-specified-location-through-python-and-selenium-using-chr) – Kays Kadhi Apr 22 '22 at 09:28
  • 1
    Yes it does, Thank you. –  Apr 22 '22 at 14:05

1 Answers1

0
df1.to_excel('output1.xlsx', engine='xlsxwriter')  

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html