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.
Metadata
Release files for cnbctv18-scraper-safe 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cnbctv18_scraper_safe-0.1.0.tar.gz | 16.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cnbctv18_scraper_safe-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.5 kB
Release files / cnbctv18_scraper_safe-0.1.0.tar.gz
| Download URL | cnbctv18_scraper_safe-0.1.0.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2be13d05a44be7da69587f6a66cd1bb1f709b538c3f2fe51cc837b1b59f3876
|
|
BLAKE2b-256 checksum How to use checksums |
419206f05e204b8a6bf15003f3ba7d11247c74114914ed7eef6f9aa792bc449d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / cnbctv18_scraper_safe-0.1.0-py3-none-any.whl
| Download URL | cnbctv18_scraper_safe-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47f01e326d5335d466c95373de6fab4b9714080470bd7834f52fea82f164015c
|
|
BLAKE2b-256 checksum How to use checksums |
84dd0f0af9f45715d521ec556b1ec0eb6b8f734a9e5376ddaa6aaf7fab7bd7e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for cnbctv18-scraper-safe 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.