1
from selenium import webdriver
browser=webdriver.Chrome('./chromedriver')
browser.get('https://www1.nseindia.com/products/content/equities/indices/historical_pepb.htm')

startDate=browser.find_element_by_id('fromDate')
startDate.send_keys('31-07-2000')

endDate=browser.find_element_by_id('toDate')
endDate.send_keys('30-06-2001')

peBox=browser.find_element_by_id('yield1')
peBox.click()

#getData=browser.find_element_by_id('get')
#getData.click()


#downLoadCSV=browser.find_element_by_link_text('Download file in csv format')
#downLoadCSV.click()

The above code opens Chrome browser, change as required.

I've commented out the parts that don't work. It'll take you till you have to press a button with "Get Data" written on it. Clicking on this button opens a little empty box instead of the data I need to access. This is what happens when I automate the click as well.

When I open the browser and complete the steps manually I'm able to access the data, no problem. Is the site blocking me from web-scraping? Have tried this on both Chrome and Firefox with the same results.

1 Answers1

0

Maybe you click on the wrong element. You suggest you do follow steps:

  1. Try clicking element with id 'get' on the browser console (press F12). Then run this command document.querySelector('#get').click(). If it works normally that means this '#get' element does not work via automated, you should work around by executing javascript.
  2. If clicking '#get' element by console also opens an empty box, you should try to click the parent of '#get' or its child element.

Good luck.

Duy Banh
  • 51
  • 2