Skip to main content

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

ankur_scraper-0.1.0.tar.gz (7.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.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

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

Hashes for ankur_scraper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5fe91b5c264b1b192faeb44a13153b6bc2c600e936e28d7e365ccb77e7ff3402
MD5 156ac46a1922f30dc711b8bd1d16355e
BLAKE2b-256 cc611d1bdeedf7e7429773cedcdc6feb51d38f55399832e9ae77bfa6b02219b8

See more details on using hashes here.

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

Hashes for ankur_scraper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5eb43bfe07476c64ba3b3cd4088f71e27021372252a4b7c6d7c6f9d6064ee260
MD5 f38f6a75dbbe71f3a1b007a61ca28196
BLAKE2b-256 8090cdbff7768ab981fc937734ac82b9bbe7f04f1146cbf619a4dee685b03da3

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