I am trying to write a python script to automatically download csv using the "Download CSV" button from the below link: https://chartink.com/screener/copy-supertrend-negative-breakout-1103
from selenium import webdriver
import pandas as pd
DRIVER_PATH = r"C:\Users\u123456\Downloads\chromedriver\chromedriver.exe"
d = webdriver.Chrome(executable_path=DRIVER_PATH)
d.get('https://chartink.com/screener/copy-supertrend-negative-breakout-1103')
download_button = pd.read_html(d.find_element_by_class_name('btn btn-default buttons-excel buttons-html5 btn-primary'))[0]
#table = pd.read_html(d.find_element_by_id('DataTables_Table_0').get_attribute('outerHTML'))[0]
print(download_button)
I am not finding any clue on how to click that button and download it to local drive. Any help would be highly appreciated.
Edit: I tried the below code and got it working, Now I would like to know if we can find the filename and load it into pandas dataframe.
element = d.find_element_by_link_text("Download csv")
element.click()
Thanks, mc
To click on the element Download csv you can use either of the following Locator Strategies:
Using
link_text
:Using
css_selector
:Using
xpath
:Ideally, to click on the element you need to induce WebDriverWait for the
element_to_be_clickable()
and you can use either of the following Locator Strategies:Using
LINK_TEXT
:Using
CSS_SELECTOR
:Using
XPATH
:Note: You have to add the following imports :