Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Articles

How to use an API to Fetch Nifty 50 Stock Data

To use the NSE API (or similar APIs) to fetch Nifty 50 stock data. Here’s an example in Python:

import requests
import pandas as pd

# URL for NSE's stock data (for reference)
url = "https://www.nseindia.com/api/equity-stockIndices?index=NIFTY%2050"

# Make a request
headers = {
    "User-Agent": "Mozilla/5.0"
}
response = requests.get(url, headers=headers)
data = response.json()

# Extract stock data
stocks = data["data"]
df = pd.DataFrame(stocks)

# Save to Excel
df.to_excel("Nifty_50_Stocks.xlsx", index=False)

caa October 25 2024 301 reads 4 comments Print

4 comments

Leave a Comment

Please Login to Post a Comment.
  • A
    Hi,
    Harsha here,

    i am getting error while using the code, is there and dependencies for the same?

    .venvLibsite-packagesrequestsmodels.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
    requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    - January 11 2025 10:10:49
    • A
      kindly please help here
      - January 11 2025 10:21:31
      • A
        priority symbol identifier ... chartTodayPath series meta
        0 1 NIFTY 50 NIFTY 50 ... https://nsearchives.nseindia.com/today/NIFTY-5... NaN NaN
        - January 11 2025 10:22:01
        • A
          priority symbol identifier ... chartTodayPath series meta
          0 1 NIFTY 50 NIFTY 50 ... https://nsearchives.nseindia.com/today/NIFTY-5... NaN NaN

          showing as NaN
          - January 11 2025 10:22:24
          Sign In
          Not a member yet? Click here to register.
          Forgot Password?
          Users Online Now
          Guests Online 3
          Members Online 0

          Total Members: 17
          Newest Member: apitech