A robust website scraper that supports static and dynamic pages with intelligent content extraction.
Project description
๐ท๏ธ Ankur Scraper
Ankur Scraper is a modular, production-ready website scraping tool built with Python. It crawls and extracts structured content from websites โ including dynamic pages rendered with JavaScript โ and saves the results in a clean JSON format.
๐ Features
- โ Crawl internal links (with max depth)
- โ Extract visible, structured text (section-wise)
- โ Supports static and dynamic (JS-rendered) pages
- โ
Respects
robots.txt - โ CLI interface with arguments
- โ Logs everything to file + rich-colored terminal
- โ Testable, extensible, and publishable as a Python package
๐ฆ Project Structure
ankur_scraper/
โโโ ankur_scraper
โ โโโ core/ # Crawling and extraction logic
โ โโโ logs/ # Package-level logs
โ โโโ cli.py # Command-line interface
โ โโโ dispatcher.py # Orchestrates scraper execution
โ โโโ _version.py
โโโ tests/ # Unit & integration tests
โโโ docs/ # ๐ Documentation (per-module)
โโโ logging_config.py
โโโ setup.py
โโโ requirements.txt
โโโ README.md
๐ Module Documentation
- Core Scrapers (
core/) - Command Line Interface (
cli.py) - Dispatcher (
dispatcher.py) - Logging System
- Testing Guide
๐ง Installation
Clone the project and install dependencies:
git clone https://github.com/your-org/ankur_scraper.git
cd ankur_scraper
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txt
# Install Playwright drivers (for dynamic scraping)
playwright install
๐น๏ธ Usage (CLI)
python -m ankur_scraper.cli \
--url "https://example.com" \
--depth 1 \
--dynamic \
--timeout 10
Command Line Options
| Option | Description |
|---|---|
--url |
Starting URL to scrape (required) |
--depth |
How deep to crawl within the domain |
--dynamic |
Use dynamic scraping (Playwright) |
--timeout |
Timeout for each page (seconds) |
๐ Usage Examples
# Basic usage
ankur-scraper --url https://example.com
# With depth and output
ankur-scraper --url https://example.com --depth 2
# With dynamic scraping and timeout
ankur-scraper --url https://example.com --dynamic --timeout 30
from ankur_scraper.dispatcher import run_scraper
data = run_scraper("https://example.com/", depth=1)
{
"data": [
{
"content": "...",
"metadata": {...}
}
],
"summary": {
"successful_pages": success_count,
"failed_pages": fail_count,
"total_sections": total_sections
}
}
๐งช Running Tests
Unit tests:
pytest tests/ --tb=short
Integration tests (live web):
pytest tests/test_integration.py -m integration
Add pytest.ini for markers:
[pytest]
markers =
integration: mark tests as integration
๐ Output Format
Every page section is saved as a structured object:
{
"content": "Text content here...",
"metadata": {
"section": "About Us",
"source_url": "https://example.com/about",
"extraction_time": "2025-07-14 12:34:56"
}
}
๐ Logging
Logs are written to both terminal and file:
logs/info.logโ general operationslogs/error.logโ failed links and errorslogs/general.logโ warnings, summaries
Terminal output is rich-colored with emojis and timestamps. (See Logging Docs for details.)
๐ฆ Packaging & Publishing
This scraper is structured as a pip-installable package.
Install locally:
pip install .
Run from anywhere:
ankur-scraper --url "https://example.com"
Publish to PyPI
pip install build twine
python -m build
twine upload dist/*
โ ๏ธ Update version in setup.py before publishing!
๐ Dependencies
httpxโ Fast, async-capable HTTP requestsbeautifulsoup4 + lxmlโ HTML parsingtldextractโ Domain filteringplaywrightโ JS rendering (headless)richโ Beautiful terminal outputpytestโ Testing
๐ค Contributing
- Fork the repo
- Make changes in a branch
- Run tests:
pytest - Submit a PR
๐ง Future Roadmap
- Save to Markdown or plaintext
- URL exclusion filters
- Config file / ENV mode
- Docker support
- CI/CD pipeline
๐งโ๐ป Maintainer
Made with โค๏ธ by Ankur Global Solutions
Project details
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 ankur_scraper-0.1.6.tar.gz.
File metadata
- Download URL: ankur_scraper-0.1.6.tar.gz
- Upload date:
- Size: 30.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33ca60c224b0f004d7233be415a02d055e371e2f5020f8bd4964206a625ac740
|
|
| MD5 |
8cc7f3b19d18de6fb187012b78dcd537
|
|
| BLAKE2b-256 |
c9b5b6a1d0fb358433738a45c4c32a791488a087ddc0d4e2f67600bb074d0f90
|
File details
Details for the file ankur_scraper-0.1.6-py3-none-any.whl.
File metadata
- Download URL: ankur_scraper-0.1.6-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55ef21c76dba808c03fbbde97caf53b948c23d71f8cb6f144bd02b3cfa9b6df6
|
|
| MD5 |
e474f267e99309572094adc03f07edf4
|
|
| BLAKE2b-256 |
54330299f1a5a429e6858a6a27555af18666ad970059a8d6946af7096ae7569d
|