I have a question regarding accessing stock data from NSE. In my project, I am tasked with downloading the daily bhavcopy of stocks. To achieve this, I’ve implemented web scraping using Python. The process successfully retrieves data, but I’ve encountered an issue where it fails to fetch data for the most recent 4 days. Here is the URL format I am using in my code:
url = f”https://archives.nseindia.com/content/historical/EQUITIES/{date.year}/{date.strftime(‘%b’).upper()}/cm{date.strftime(‘%d%b%Y’).upper()}bhav.csv.zip”
response = requests.get(url, stream=True)
Additionally, I’ve noticed discrepancies between the data obtained programmatically versus directly downloading the bhavcopy file from NSE’s website. The programmatically retrieved data contains less information and appears to be formatted differently from the direct download. As a newcomer to this field, I would appreciate clarification on whether the URL format I’m using is correct or if NSE provides data in a different manner programmatically.
Thank you for your assistance.
In attempting to download daily stock data from NSE, I utilized web scraping with Python to fetch the bhavcopy files. Specifically, I constructed URLs dynamically based on the date to access the historical data archives. Here’s the code snippet I used:
url = f”https://archives.nseindia.com/content/historical/EQUITIES/{date.year}/{date.strftime(‘%b’).upper()}/cm{date.strftime(‘%d%b%Y’).upper()}bhav.csv.zip”
response = requests.get(url, stream=True)
My expectation was to retrieve daily bhavcopy files seamlessly, including data for the most recent dates. However, I encountered an issue where the data retrieval failed for the last 4 days. Moreover, when comparing the programmatically fetched data with directly downloaded bhavcopy files from NSE’s website, I noticed discrepancies in information and file structure.
As a result, I’m seeking clarification on whether the URL format I’m using is correct for accessing recent data or if there’s an alternative method recommended by NSE for such data retrieval programmatically.
jkkn clg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.