Skip to main content

Collection of different tools for async web scraping, crawling and parsing

Project description

aiofetch

A Python toolkit for asynchronous web scraping with built-in error tracking and metadata management.

Features

Web Processing

  • Asynchronous file downloading with progress tracking
  • Rate limiting with configurable delays
  • Smart retry logic with timeout handling
  • Domain-aware crawling with URL validation

Content Processing

  • Flexible HTML content parsing
  • Custom selector-based metadata extraction
  • Automated link and image extraction
  • URL normalization and path handling

File & Data Management

  • Asynchronous file operations
  • Concurrent chunk-based downloads
  • Smart path handling and file naming
  • JSON data management with validation

Error Handling & Progress Tracking

  • Comprehensive error tracking and reporting
  • Progress monitoring for long operations
  • Detailed logging with configurable outputs
  • Operation statistics and summaries

Metadata Management

  • Efficient in-memory caching
  • Field-based search functionality
  • Automatic metadata indexing
  • Structured data validation

Installation

pip install aiofetch

Key Components

  • AsyncDownloader: Parallel file downloading with progress tracking
  • BatchProcessor: Process items in configurable batches
  • RateLimiter: Control request frequency
  • MetadataExtractor: HTML metadata extraction with custom selectors
  • PathHandler: Path and filename utilities
  • FileIO: Async/sync file operations
  • BaseCrawler: Extensible crawler base class with domain validation
  • LoggerFactory: Enhanced logging with file and console outputs

Requirements

  • Python 3.9+
  • aiofiles
  • aiohttp
  • BeautifulSoup4

Quick start

import asyncio
from aiofetch import (
    AsyncDownloader,
    BaseCrawler,
    ContentParser,  
    MetadataExtractor,
    FileIO,
    RateLimiter
)


async def main():
    # Initialize components
    crawler = BaseCrawler("https://example.com", concurrent_limit=5)
    downloader = AsyncDownloader(concurrent_limit=10)
    parser = ContentParser()
    extractor = MetadataExtractor()
    file_io = FileIO()
    rate_limiter = RateLimiter(requests_per_second=2)

    async with crawler:
        # Fetch and parse page
        html = await crawler.fetch_page("https://example.com/products")
        
        if html:
            # Extract links and metadata
            links = parser.extract_links(html, base_url=crawler.base_url)
            metadata = extractor.extract_from_html(html, {
                'title': 'h1.product-title',
                'price': ('.price', 'data-amount'),
                'description': 'meta[name="description"]',
                'images': ('img.product-image', 'src')
            })

            # Download images with rate limiting
            image_urls = [(img['url'], f"images/{i}.jpg") 
                         for i, img in enumerate(metadata.get('images', []))]
            
            async with rate_limiter:
                await downloader.download_batch(image_urls)

            # Save extracted data
            await file_io.write_json(metadata, 'data/product_metadata.json')
            
            # Results:
            print(f"Processed {len(links)} links")
            print(f"Downloaded {downloader.downloaded} images")
            print(f"Saved metadata to data/product_metadata.json")


if __name__ == "__main__":
    asyncio.run(main())

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or Issue.

Author

Akram Rakhmetulla (akram042006@gmail.com)

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

aiofetch-0.0.5.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

aiofetch-0.0.5-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file aiofetch-0.0.5.tar.gz.

File metadata

  • Download URL: aiofetch-0.0.5.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for aiofetch-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f8a630914af38b816627c888183d96ea6f7ab14a8a88962d40c66ff4371105a6
MD5 daa0d8797ea3ea3a6928fb2ed416418c
BLAKE2b-256 a593fd51a5ded6afbaa5edf9ca8c6d8660141244ddad09ce77414dddc58675ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiofetch-0.0.5.tar.gz:

Publisher: workflow.yml on spike1236/aiofetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiofetch-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: aiofetch-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for aiofetch-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c973a47f62f8048df5aabe106099f40c74c0ea4161c5fd1612b50b0312d3880f
MD5 7be59a9540e2c900c8c63be3a8334751
BLAKE2b-256 e42dd838924089e3ccb6bac0329ad9a13537e72f6e46b8f2771986320dc4c2ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiofetch-0.0.5-py3-none-any.whl:

Publisher: workflow.yml on spike1236/aiofetch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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