I want to download files from a website.
The website has a file download button.
But when I click the download button by button.click()
, the file doesn't download on Colaboratory. (It works at Juypyter Notebook.)
I googled and found a solution. My code applying the solution was as follows:
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# solution
prefs = {'download.default_directory' : "/some/path"}
options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome('chromedriver',options=options)
# Download code
xpath = '''//*[@id="glopopd_excel"]/span'''
element_get_excel = driver.find_element_by_xpath(xpath).click()
But I can't find downloaded files anywhere.
Do I have to type 'GoogleDrive path'
on prefs? (But it didn't work.)
If not, how can I download files on a click event using Selenium on Colaboratory?