A web scraping library focused on extracting website sections with standardized output format
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/
โ โโโ init.py
โ โโโ cli.py
โ โโโ core/
โ โ โโโ crawler.py
โ โ โโโ dispatcher.py
โ โ โโโ html_extractor.py
โ โ โโโ page_scraper.py
โ โโโ logging_config.py
โ โโโ logs/
โ โโโ info.log
โ โโโ error.log
โ โโโ general.log
โโโ tests/
โ โโโ test_crawler.py
โ โโโ test_html_extractor.py
โ โโโ test_page_scraper.py
โ โโโ test_integration.py
โ โโโ conftest.py
โโโ requirements.txt
โโโ setup.py
โโโ README.md
๐ง 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 \
--output results.json \
--dynamic \
--timeout 10
Command Line Options
| Option | Description |
|---|---|
--url |
Starting URL to scrape (required) |
--depth |
How deep to crawl within the domain |
--output |
File path to save JSON output |
--dynamic |
Use dynamic scraping (Playwright) |
--timeout |
Timeout for each page (seconds) |
Usage Examples
# Basic usage
script --url https://example.com
# With depth and output
script --url https://example.com --depth 2 --output results.json
# With dynamic scraping and timeout
script --url https://example.com --dynamic --timeout 30
๐งช Running Tests
Unit Tests
pytest tests/ --tb=short
Integration Tests (Live Web)
pytest tests/test_integration.py -m integration
Integration tests make real HTTP calls to sites like example.com.
Add pytest.ini for markers:
# pytest.ini
[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 operations
- logs/error.log: failed links and errors
- logs/general.log: warnings, summaries
Terminal output is rich-colored with emojis and timestamps.
๐ฆ Packaging & Publishing
This scraper is fully structured as a pip-installable package.
Install Locally for CLI Use
pip install .
Now you can run:
ankur-scraper --url "https://..." --output output.json
Publish to PyPI
Ensure you have build and twine:
pip install build twine
Build and publish
python -m build
twine upload dist/*
Update version in setup.py before publishing!
๐ Dependencies
- httpx: Fast, async-capable HTTP requests
- beautifulsoup4 + lxml: HTML parsing
- tldextract: Domain filtering
- playwright: JS rendering (headless)
- rich: Beautiful terminal output
- pytest: Testing
๐ค Contributing
- Fork the repo
- Make changes in a branch
- Run tests: pytest
- Submit a PR
๐ง Future Ideas
- Save to Markdown or plaintext
- URL exclusion filters
- Config file/ENV mode
- Docker support
- CI/CD for publishing
๐งโ๐ป 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.0.tar.gz.
File metadata
- Download URL: ankur_scraper-0.1.0.tar.gz
- Upload date:
- Size: 7.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 |
5fe91b5c264b1b192faeb44a13153b6bc2c600e936e28d7e365ccb77e7ff3402
|
|
| MD5 |
156ac46a1922f30dc711b8bd1d16355e
|
|
| BLAKE2b-256 |
cc611d1bdeedf7e7429773cedcdc6feb51d38f55399832e9ae77bfa6b02219b8
|
File details
Details for the file ankur_scraper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ankur_scraper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 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 |
5eb43bfe07476c64ba3b3cd4088f71e27021372252a4b7c6d7c6f9d6064ee260
|
|
| MD5 |
f38f6a75dbbe71f3a1b007a61ca28196
|
|
| BLAKE2b-256 |
8090cdbff7768ab981fc937734ac82b9bbe7f04f1146cbf619a4dee685b03da3
|