I want to automatically get data from the NSE site link of which I have mentioned in my code. The issue I am facing is that the Get Data button on the website is not working with the code and the browser gets stuck without displaying any data thereafter. Moreover, I have written a panda code to get the data on the webpage after filling in all the information but that is also not working.
from selenium import webdriver
import time
import pandas as pd
a=input("Symbol\n")
web=webdriver.Chrome()
web.get('https://www1.nseindia.com/products/content/equities/equities/eq_security.htm')
time.sleep(5)
Data=web.find_element_by_xpath('//*[@id="dataType"]/option[1]')
Data.click()
Symbol=web.find_element_by_xpath('//*[@id="symbol"]')
Symbol.send_keys(a)
Month=web.find_element_by_xpath('//*[@id="dateRange"]/option[8]')
Month.click()
time.sleep(2)
Go=web.find_element_by_xpath('//*[@id="get"]')
Go.click()
df=pd.read_html('https://www1.nseindia.com/products/content/equities/equities/eq_security.htm')
print(df[0])
CodePudding user response:
This works fine for me by using java script executor
from selenium import webdriver
import time, warnings
a=input("Symbol: ")
warnings.filterwarnings("ignore", category=DeprecationWarning)
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options)
driver.get('https://www1.nseindia.com/products/content/equities/equities/eq_security.htm')
time.sleep(5)
Data = driver.find_element_by_xpath('//*[@id="dataType"]/option[1]')
Data.click()
Symbol = driver.find_element_by_xpath('//*[@id="symbol"]')
Symbol.send_keys(a)
Month = driver.find_element_by_xpath('//*[@id="dateRange"]/option[8]')
Month.click()
time.sleep(2)
driver.execute_script("javascript:document.getElementById('submitMe').click()")
#driver.execute_script("javascript:submitData();") ## this one also works
CodePudding user response:
The easiest way to get NSE India is to use the nsepython
package:
pip install nsepython
Read the documentation