Polite, robots.txt-respecting CNBC-TV18 news collector for Indian-market sentiment and swing-trading research.
Project description
cnbctv18_scraper_safe
A polite, robots.txt-respecting Python library for collecting public CNBC-TV18 news/financial content for research and NLP sentiment training only.
What it does NOT do
- Does not bypass logins, paywalls, captchas, Cloudflare, or anti-bot systems.
- Does not ignore
robots.txtor rate limits. - Does not scrape personal data.
If robots.txt cannot be loaded or disallows a URL, the fetcher refuses (fail-closed).
Install
pip install -r requirements.txt
Quick start
from cnbctv18_scraper import (
collect_all_categories,
parse_articles_dataframe,
filter_valid_articles,
add_content_hash, deduplicate,
add_sentiment_column, add_impact_column,
add_stock_symbols_column,
save_dataframe, save_unique_to_sqlite,
)
import pandas as pd
urls = collect_all_categories(["markets", "economy", "earnings"])
articles = parse_articles_dataframe(urls["url"].head(20).tolist())
articles = filter_valid_articles(articles) # quality filter
articles = deduplicate(add_content_hash(articles)) # content-hash dedup
articles = add_sentiment_column(articles) # +sentiment_*
articles = add_impact_column(articles) # +impact_score
# Optional ticker mapping (CSV with columns: symbol,name)
articles = add_stock_symbols_column(articles, pd.read_csv("stocks.csv"))
articles["news_id"] = articles["content_hash"]
save_dataframe(articles, "articles", fmt="csv")
save_unique_to_sqlite(articles) # upsert into SQLite
CLI
python main.py --category markets --limit-per-category 20 --max-articles 100
python main.py --category all --max-articles 50 --stocks stocks.csv
python main.py --category economy --no-sqlite
CLI flags: --category, --limit-per-category, --max-articles, --stocks, --db, --no-sqlite.
Pipeline
Category + RSS + Sitemap URLs
→ robots check (built into fetcher)
→ fetch allowed pages (delay + retry + timeout)
→ parse article
→ quality filter (is_valid_article)
→ deduplicate (content_hash)
→ stock mapping (map_stock_symbols)
→ sentiment score (add_sentiment_column)
→ impact score (add_impact_column)
→ store CSV + SQLite (save_unique_to_sqlite)
Layout
cnbctv18_scraper_safe/
├── requirements.txt
├── main.py
├── README.md
├── cnbctv18_scraper/
│ ├── __init__.py
│ ├── config.py # base URL, category map, headers, delays
│ ├── http_client.py # requests session w/ retries + backoff
│ ├── robots_checker.py # cached robots.txt enforcement
│ ├── html_collector.py # polite single-page fetcher (BeautifulSoup)
│ ├── url_collector.py # discover article URLs from category pages
│ ├── parser.py # parse + quality-filter articles
│ ├── dedup.py # content_hash + deduplicate
│ ├── sentiment.py # sentiment + impact + stock-symbol mapping
│ └── storage.py # CSV / Parquet / JSON + SQLite upsert
└── data/
├── raw/ # raw HTML dumps
└── clean/ # CSV/Parquet/JSON outputs
Categories
Configured in cnbctv18_scraper/config.py — includes latest_news, markets,
stocks, economy, finance, business, earnings, technology,
real_estate, auto, telecom, aviation, infrastructure, healthcare,
agriculture, commodities, currency, expert_views, personal_finance,
videos, and more.
Settings (in config.py)
| Setting | Default |
|---|---|
REQUEST_DELAY_SECONDS |
2 |
REQUEST_TIMEOUT_SECONDS |
20 |
MAX_RETRIES |
3 |
RETRY_BACKOFF |
2 |
HEADERS["User-Agent"] |
BharatSwingAIResearchBot/1.0 |
Sentiment
sentiment.py ships a small finance lexicon (gain/loss/beat/miss/upgrade/...).
It's a baseline only — swap in FinBERT or a fine-tuned model for serious work.
License / use
Research and educational use only. You are responsible for complying with CNBC-TV18's Terms of Service and applicable law in your jurisdiction.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cnbctv18_scraper_safe-0.1.0.tar.gz.
File metadata
- Download URL: cnbctv18_scraper_safe-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2be13d05a44be7da69587f6a66cd1bb1f709b538c3f2fe51cc837b1b59f3876
|
|
| MD5 |
0bbbf29426820f769f615cf1ed4398b4
|
|
| BLAKE2b-256 |
419206f05e204b8a6bf15003f3ba7d11247c74114914ed7eef6f9aa792bc449d
|
File details
Details for the file cnbctv18_scraper_safe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cnbctv18_scraper_safe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47f01e326d5335d466c95373de6fab4b9714080470bd7834f52fea82f164015c
|
|
| MD5 |
03939d8a1e03c850cf9bc70c5a3364e0
|
|
| BLAKE2b-256 |
84dd0f0af9f45715d521ec556b1ec0eb6b8f734a9e5376ddaa6aaf7fab7bd7e5
|