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.2.tar.gz (14.1 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.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ankur_scraper-0.1.2.tar.gz
  • Upload date:
  • Size: 14.1 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.2.tar.gz
Algorithm Hash digest
SHA256 02ae7bba8dbd34a2face8f706b0590b3985d23221e1ea3db2e769f8831b77045
MD5 0fdbf167565ff2674d504e1b2cfeb094
BLAKE2b-256 80d8eb4250900a67c983a142e3de22c0e3827bd2ffff1b2fd6b57a7cc35220a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ankur_scraper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed2b16ffebcc2f2c547b688b2855699d0aff6806fc7dfdf531090984a407f842
MD5 189cbbae127f0cb5462c6ee5417fb2ac
BLAKE2b-256 127851d56d51363ffa668c0c85e6e3a64c60a699f9c84d2bf3d57631f6cccab7

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