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
โ”‚   โ”œโ”€โ”€ 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

๐Ÿ”ง 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
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

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 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.4.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.4-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ankur_scraper-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 3a52256e9839515f09bd06b7793b2445e81a249067c1a386786c4a4987a5febf
MD5 308007166ee2faf0342b6bc247a28670
BLAKE2b-256 78f11f867e8b40b251d8f363584ebbcbb2692c4f0bc662855e7b639aa6748c21

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ankur_scraper-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b88576475b0d48493375fa6d7a80f15a95c06ae54cadf5730a658d2dfb00f995
MD5 1d6e7edb09d5f3ec576b15ccc67a8e6f
BLAKE2b-256 e7665d207dcc26950b93c983c85023e73ad9d8915cec250e2eb4e832e9bc137a

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