1

Here is my Python code:

import requests

url = 'https://www1.nseindia.com/live_market/dynaContent/live_watch/stock_watch/juniorNiftyStockWatch.json'

headers = {
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0, no-cache, no-store',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.0.2990 Safari/537.36',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-US,en;q=0.9,hi;q=0.8'
}

cookie_dict = {
    'bm_sv': 'FE5D5202FA442377EAE6BE578E5AE53D~TmgiDfrRzUs3GLDNWdi+VYOGUgD/J5uggMUSrRYzOob13kW5hAIyKjXHPWK42UDCM69u2LxxjUmIZ3uo/6orCmkSTim/QNEqHDMaqyU+lnjwtT3j4bI7rpt2OfhdZ/wPYtAQPaG7IJQj8fFUKxNm0EtMj/ZHW8jDRzOvy0JfZhk='
}

session = requests.session()

for cookie in `cookie_dict`:

    session.cookies.set(cookie, cookie_dict[cookie])
    json = session.get(url, headers = headers).json()
    
    print(json)

Here is the sample output for 2 stocks:


{
    "declines":18,
    "data":[
        {
            "symbol":"IDEA",
            "open":"4.25",
            "high":"4.80",
            "low":"4.20",
            "ltP":"4.55",
            "ptsC":"0.35",
            "per":"8.33",
            "trdVol":"9,245.45",
            "trdVolM":"924.54",
            "ntP":"420.67",
            "mVal":"4.21",
            "wkhi":"15.00",
            "wklo":"2.40",
            "wkhicm_adj":"183.70",
            "wklocm_adj":"125.10",
            "xDt":"31-DEC-2999",
            "cAct":"-",
            "previousClose":"4.20",
            "dayEndClose":"4.6",
            "iislPtsChange":"0.40",
            "iislPercChange":"9.52",
            "yPC":"-68.18",
            "mPC":"42.19"
        },
        {
            "symbol":"MOTHERSUMI",
            "open":"78.50",
            "high":"85.00",
            "low":"78.10",
            "ltP":"80.60",
            "ptsC":"3.60",
            "per":"4.68",
            "trdVol":"547.02",
            "trdVolM":"54.70",
            "ntP":"450.85",
            "mVal":"4.51",
            "wkhi":"151.00",
            "wklo":"48.65",
            "wkhicm_adj":"450.70",
            "wklocm_adj":"178.25",
            "xDt":"12-MAR-2020",
            "cAct":"INTERIM DIVIDEND - RS 1.50 PER SHARE",
            "previousClose":"77.00",
            "dayEndClose":"80.45",
            "iislPtsChange":"3.45",
            "iislPercChange":"4.48",
            "yPC":"-37.54",
            "mPC":"43.42"
        }
    ]
}

How to write this required table format in an Excel sheet while continuously fetching data with a time interval and setting a running time period for the program.

No, symbol, open, high, low, ltp, ptsc, per, trdvol, trdvolm, ntp, mval', wkhi, wklo, wkhicm_adj
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Durai
  • 11
  • 2

0 Answers0