This Python script scrapes the top 5 gainers and losers from the NSE India website using Selenium and sends an email with the data in tabular HTML format.
- Scrapes top 5 gainers and losers from NSE daily market snapshot.
- Sends an HTML email with the extracted data.
- Uses environment variables for secure credentials.
- Configurable SMTP email delivery (supports Gmail, Outlook, etc.).
- Python 3.x
- Selenium
- Chrome WebDriver (via
webdriver-manager) smtplibfor sending emailsdotenvfor managing environment variables
git clone https://github.com/your-username/nse-market-snapshot.git
cd nse-market-snapshot
pip install -r requirements.txt
Create a .env file in the root directory with the following content:
SMTP_SERVER = smtp.gmail.com
SMTP_PORT = 587
SENDER_EMAIL = your_email@gmail.com
SENDER_PASSWORD = your_email_password_or_app_password
RECEIVER_EMAIL = receiver_email@example.com
pip install -r requirements.txt
This will:
- Open NSE website using headless Chrome
- Navigate to the "Top Gainers/Losers" section
- Extract top 5 from each
- Send a formatted HTML email
Schedule the script with cron (Linux/macOS) or Task Scheduler (Windows) for daily execution. Example cron entry to run every weekday at 4:15 PM:
15 16 * * 1-5 /usr/bin/python3 /path/to/main.py
Do not hardcode credentials. Use the .env file and keep it out of version control (.gitignore it).
A sample email body:
Subject: 📈 NSE Top 5 Gainers and Losers Today
Top 5 Gainers
| SYMBOL | LTP | %CHNG |
|---|---|---|
| ABC | ₹123.45 | +5.6% |
| ... | ... | ... |
Top 5 Losers
| SYMBOL | LTP | %CHNG |
|---|---|---|
| XYZ | ₹98.76 | -4.3% |
| ... | ... | ... |
This project is for educational and personal use only. NSE data is copyrighted and scraping may be restricted.
Rishabh Dhawad
Made with ❤️ and Python 🐍