I am trying to get data showing on the chart when I move the mouse. NSE chart Images
Asked
Active
Viewed 334 times
-3
-
and where is your code ? If page uses JavaScript then you may need Selenium or you should check what url uses JavaScript to read data and use it to get data. – furas Aug 11 '20 at 23:08
-
you could add link to this page. – furas Aug 11 '20 at 23:12
-
examples from other questions for nseindia.com but I don't know if there is example for page with chart: https://github.com/furas/python-examples/tree/master/__scraping__/nseindia.com%20-%20requests – furas Aug 11 '20 at 23:14
-
Does this answer your question? [Dynamic dropdown doesn't populate with auto suggestions on https://www.nseindia.com/ when values are passed using Selenium and Python](https://stackoverflow.com/questions/62457093/dynamic-dropdown-doesnt-populate-with-auto-suggestions-on-https-www-nseindia) – Nad Pat Sep 03 '21 at 17:41
1 Answers
1
This chart read data from urls
https://www.nseindia.com/api/chart-databyindex?index=BERGEPAINTEQN
https://www.nseindia.com/api/chart-databyindex?index=BERGEPAINTEQN&preopen=true
and you can get it with requests
This page needs header User-Agent
but it can be even short 'Mozilla/5.0'
.
import requests
import datetime
headers = {'User-Agent': 'Mozilla/5.0'}
url = 'https://www.nseindia.com/api/chart-databyindex?index=BERGEPAINTEQN'
#url = 'https://www.nseindia.com/api/chart-databyindex?index=BERGEPAINTEQN&preopen=true'
r = requests.get(url, headers=headers)
# --- response ---
#print(r.status_code)
data = r.json()
print('name:', data['name'])
print('identifier:', data['identifier'])
print('close price:', data['closePrice'])
prices = data['grapthData'][:10]
for item in prices:
dt = datetime.datetime.utcfromtimestamp(item[0]/1000)
value = item[1]
print(dt, value)
Result
name: BERGEPAINT
identifier: BERGEPAINTEQN
close price: 551.45
2020-08-11 09:15:00 553.7
2020-08-11 09:15:01 553.7
2020-08-11 09:15:02 553
2020-08-11 09:15:03 553.95
2020-08-11 09:15:04 553.9
2020-08-11 09:15:05 553.6
2020-08-11 09:15:06 553.85
2020-08-11 09:15:07 553.35
2020-08-11 09:15:08 553.35
2020-08-11 09:15:09 553.35

furas
- 134,197
- 12
- 106
- 148
-
Thank you very much sir, It's working excellent without a single error. – vpnkumar Aug 13 '20 at 13:49