Nse Stock Index Scraper
Pricing
$20.00/month + usage
Go to Store
Nse Stock Index Scraper
Scrape live prices for NSE stocks and indices from Google Finance. Customize the tickers you want to track, get structured output with price and timestamp, and automate your data collection for research, dashboards, or trading insights. Fast, reliable, and easy to use!
0.0 (0)
Pricing
$20.00/month + usage
0
Total users
1
Monthly users
1
Last modified
2 days ago
.actor/actor.json
{ "actorSpecification": 1, "name": "nse-stock-index-scraper", "title": "Project Playwright Crawler JavaScript", "description": "Crawlee and Playwright project in JavaScript.", "version": "0.0", "meta": { "templateId": "js-crawlee-playwright-chrome" }, "input": "./input_schema.json", "dockerfile": "../Dockerfile"}
.actor/input_schema.json
{ "schemaVersion": 1, "title": "Stock Price Scraper Input", "type": "object", "properties": { "tickers": { "title": "Stock Tickers", "type": "array", "description": "A list of NSE stock ticker symbols or index symbols (e.g., NIFTY_50:INDEXNSE, NIFTY_BANK:INDEXNSE) to fetch prices for.", "editor": "stringList", "default": [ "TCS", "RVNL", "IRFC", "ANGELONE", "NIFTY_50:INDEXNSE", "NIFTY_BANK:INDEXNSE" ] } }, "required": ["tickers"] }
src/main.js
1import { Actor } from 'apify';2import { chromium } from 'playwright';3
4await Actor.init();5
6const tickers = [7 "TCS:NSE", "RVNL:NSE", "IRFC:NSE", "ANGELONE:NSE",8 "NIFTY_50:INDEXNSE", "NIFTY_BANK:INDEXNSE"9];10
11const browser = await chromium.launch();12const page = await browser.newPage();13
14try {15 let iteration = 0;16 const maxIterations = 100; // Example: limit to 100 iterations17
18 while (iteration < maxIterations) {19 for (const ticker of tickers) {20 const url = `https://www.google.com/finance/quote/${ticker}`;21 try {22 await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });23
24 let price;25 try {26 // Try stock selector27 price = await page.$eval('div.YMlKec.fxKbKc', el => el.textContent.trim());28 } catch {29 // Fallback to index selector30 price = await page.$eval('div.YMlKec', el => el.textContent.trim());31 }32
33 // Validate price34 if (!price || isNaN(parseFloat(price.replace(/[^0-9.]/g, '')))) {35 throw new Error(`Invalid price format for ${ticker}: ${price}`);36 }37
38 const result = {39 ticker,40 price,41 scrapedAt: new Date().toISOString()42 };43
44 console.log('✅ Scraped:', result);45 await Actor.pushData(result);46 } catch (err) {47 console.error(`❌ Failed to scrape ${ticker}:`, err.message);48 // Optional: Log page content for debugging49 // const content = await page.content();50 // console.log(`Page content for ${ticker}:`, content.slice(0, 500));51 }52 }53 iteration++;54 await new Promise(res => setTimeout(res, 5000)); // Configurable delay55 }56} finally {57 await browser.close();58 await Actor.exit();59}
src/routes.js
1import { createPlaywrightRouter, Dataset } from 'crawlee';2
3export const router = createPlaywrightRouter();4
5router.addDefaultHandler(async ({ enqueueLinks, log }) => {6 log.info(`enqueueing new URLs`);7 await enqueueLinks({8 globs: ['https://apify.com/*'],9 label: 'detail',10 });11});12
13router.addHandler('detail', async ({ request, page, log }) => {14 const title = await page.title();15 log.info(`${title}`, { url: request.loadedUrl });16
17 await Dataset.pushData({18 url: request.loadedUrl,19 title,20 });21});
.dockerignore
# configurations.idea.vscode.zed
# crawlee and apify storage foldersapify_storagecrawlee_storagestorage
# installed filesnode_modules
# git folder.git
.editorconfig
root = true
[*]indent_style = spaceindent_size = 4charset = utf-8trim_trailing_whitespace = trueinsert_final_newline = trueend_of_line = lfquote_type = single
.gitignore
# This file tells Git which files shouldn't be added to source control
.DS_Store.idea.vscode.zeddistnode_modulesapify_storagestorage
# Added by Apify CLI.venv
.prettierrc
{ "printWidth": 120, "tabWidth": 4, "singleQuote": true}
Dockerfile
# Specify the base Docker image. You can read more about# the available images at https://crawlee.dev/docs/guides/docker-images# You can also use any other image from Docker Hub.FROM apify/actor-node-playwright-chrome:22-1.53.2
# Check preinstalled packagesRUN npm ls crawlee apify puppeteer playwright
# Copy just package.json and package-lock.json# to speed up the build using Docker layer cache.COPY package*.json Dockerfile ./
# Check Playwright version is the same as the one from base image.RUN node check-playwright-version.mjs
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --omit=dev --omit=optional \ && echo "Installed NPM packages:" \ && (npm list --omit=dev --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version \ && rm -r ~/.npm
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Run the image. If you know you won't need headful browsers,# you can remove the XVFB start script for a micro perf gain.CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
eslint.config.mjs
1import prettier from 'eslint-config-prettier';2
3import apify from '@apify/eslint-config/js.js';4
5// eslint-disable-next-line import/no-default-export6export default [{ ignores: ['**/dist'] }, ...apify, prettier];
package.json
{ "name": "nse-stock-index-scraper", "version": "0.0.1", "type": "module", "description": "This is an example of an Apify Actor.", "dependencies": { "apify": "^3.4.2", "crawlee": "^3.13.8", "playwright": "1.53.2" }, "devDependencies": { "@apify/eslint-config": "^1.0.0", "eslint": "^9.29.0", "eslint-config-prettier": "^10.1.5", "prettier": "^3.5.3" }, "scripts": { "start": "node src/main.js", "format": "prettier --write .", "format:check": "prettier --check .", "lint": "eslint", "lint:fix": "eslint --fix", "test": "echo \"Error: oops, the Actor has no tests yet, sad!\" && exit 1", "postinstall": "npx crawlee install-playwright-browsers" }, "author": "It's not you it's me", "license": "ISC"}