Skip to main content

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


๐Ÿ”ง 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 operations
  • logs/error.log โ†’ failed links and errors
  • logs/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 requests
  • beautifulsoup4 + lxml โ€“ HTML parsing
  • tldextract โ€“ Domain filtering
  • playwright โ€“ JS rendering (headless)
  • rich โ€“ Beautiful terminal output
  • pytest โ€“ Testing

๐Ÿค Contributing

  1. Fork the repo
  2. Make changes in a branch
  3. Run tests: pytest
  4. 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

ankur_scraper-0.1.5.tar.gz (27.8 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.5-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ankur_scraper-0.1.5.tar.gz
  • Upload date:
  • Size: 27.8 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.5.tar.gz
Algorithm Hash digest
SHA256 2f82811277d6ab6443e3cfdcb8114b28b2507941dfdb26e235f8f6fd1f7d7517
MD5 3492d7e9b6da8f9aaea4a53a8b331430
BLAKE2b-256 5b276b70893bc2f3539a1aac6b0b94a41b9fe021e8a48dde3d2c1f23d185462f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ankur_scraper-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 28.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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b6a60ca235f9302aab11e09efe65280b5a63f025d17c62dc1eb2198c919b7aa0
MD5 aad2ae1f6652b2b5ae12a9f622ec35fd
BLAKE2b-256 0b508a734c5e685d1ec25fbe5f9bee4eac9a1eb4e808197d22d02a457d14b1bc

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