Skip to main content

A robust website scraper that supports static and dynamic pages.

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 \
  --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
script --url https://example.com

# With depth and output
script --url https://example.com --depth 2

# 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://..."

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 Structure

ankur_scraper/
โ”œโ”€โ”€ ankur_scraper
โ”‚   โ”œโ”€โ”€ core
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ crawler.py
โ”‚   โ”‚   โ”œโ”€โ”€ html_extractor.py
โ”‚   โ”‚   โ””โ”€โ”€ page_scraper.py
โ”‚   โ”œโ”€โ”€ logs
โ”‚   โ”‚   โ”œโ”€โ”€ error.log
โ”‚   โ”‚   โ”œโ”€โ”€ general.log
โ”‚   โ”‚   โ””โ”€โ”€ info.log
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ _version.py
โ”‚   โ”œโ”€โ”€ cli.py
โ”‚   โ””โ”€โ”€ dispatcher.py
โ”œโ”€โ”€ logs
โ”‚   โ”œโ”€โ”€ error.log
โ”‚   โ”œโ”€โ”€ general.log
โ”‚   โ””โ”€โ”€ info.log
โ”œโ”€โ”€ tests
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_crawler.py
โ”‚   โ”œโ”€โ”€ test_html_extractor.py
โ”‚   โ”œโ”€โ”€ test_integration.py
โ”‚   โ””โ”€โ”€ test_page_scraper.py
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ generate_tree.py
โ”œโ”€โ”€ logging_config.py
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ pytest.ini
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ setup.py
โ”œโ”€โ”€ test.py
โ””โ”€โ”€ test_output.json

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

ankur_scraper-0.1.3.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ankur_scraper-0.1.3-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file ankur_scraper-0.1.3.tar.gz.

File metadata

  • Download URL: ankur_scraper-0.1.3.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ankur_scraper-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9b61ac96262f49fe7580143b18cdfc251307b5f25654d4e10cbab00fd191467b
MD5 c5f624e38c3736c0df0ab0b3becf3a28
BLAKE2b-256 a226ce037d8adbe688a774f1bb75bb2cd238921d8451b08d00cad2687e1ebed6

See more details on using hashes here.

File details

Details for the file ankur_scraper-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ankur_scraper-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ankur_scraper-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 55de0a59d7eb1f083b61b90edccb6709eebba350b8450640842a2119cc0f89c0
MD5 d4d95d1dfe7b61dbba2f29e6e470690a
BLAKE2b-256 8c1f181db9080bec14a3cae0c01e9ecd7a3010e0915c507e85375f0968b29dfe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page