Skip to main content

Configurable crawler for web-scraping

Project description

arc-crawler

🌐 English | 日本語

arc-crawler is a flexible Python module designed to simplify complex web scraping tasks. It focuses on efficient, resumable data acquisition, structured output management, and customizable data processing.

✨ Features

  • Flexible Fetching Strategies: Supports both high-speed parallel and precise sequential URL fetching with customizable delays.
  • Resumable Progress Tracking: Automatically tracks progress, allowing seamless resumption from interruptions and incremental data appending.
  • Efficient Output Management: Writes metadata alongside fetched data, making very large output files easily accessible and queryable via built-in IndexReader.
  • Customizable Data Processing: Offers flexible callback functions for pre-request actions, post-response processing, and custom metadata indexing.

🚀 Quick Start

Installation

You can easily install arc-crawler using pip:

pip install arc-crawler

Basic Usage

This example shows you how to quickly crawl a few Wikipedia pages and save only their <body> contents using the built-in html_body_processor.

from arc_crawler import Crawler, html_body_processor


def crawl_wikipedia():
    urls_to_fetch = [
        "https://en.wikipedia.org/wiki/JavaScript",
        "https://en.wikipedia.org/wiki/Go_(programming_language)",
        "https://en.wikipedia.org/wiki/Python_(programming_language)",
        "https://en.wikipedia.org/wiki/Node.js",
    ]

    # Initialize the crawler, outputting to a new './output' directory
    crawler = Crawler(out_file_path="./output")

    # Fetch URLs, process responses to save only the <body> tag, and save to 'wiki-programming' files
    reader = crawler.get(
        urls_to_fetch,
        out_file_name="wiki-programming",
        response_processor=html_body_processor,  # Use the built-in processor
    )

    print(f"Successfully gathered {len(reader)} Wikipedia entries.")
    print(f"Dataset file is located at: {reader.path}")


if __name__ == "__main__":
    crawl_wikipedia()

📚 More Examples & Advanced Usage

For more detailed examples demonstrating advanced features like custom response/request processors, metadata indexing, and handling json content, please refer to the basic.py and advanced.py file within the repository.

Additionally, for comprehensive API documentation, including all available parameters, return types, and internal workings, explore the detailed docstrings within the arc-crawler module's source code (e.g., use help(Crawler) or help(Crawler.get) in your Python interpreter or access docs via IDE Tools).

💡 Best Practice: Separate Scraping from Parsing

For optimal efficiency and maintainability in web scraping, it is strongly recommended to prioritize saving raw, unaltered response data first within your response_processor callbacks. Avoid implementing complex parsing logic directly during the fetching phase.

This approach offers significant advantages:

  • Iterative Improvement: You can refine and improve your parsing logic on local data without needing to re-fetch everything each time.
  • Resilience & Speed: The fetching stage focuses purely on data acquisition, improving resilience to network issues and maximizing download speed.
  • Resource Management: Offload CPU and memory-intensive parsing to a separate process or script, preventing it from slowing down I/O-bound fetching operations.

In essence, with arc-crawler, focus on saving the raw source data. Parsing is a distinct, subsequent step best performed after fetching.

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

arc_crawler-0.1.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

arc_crawler-0.1.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file arc_crawler-0.1.0.tar.gz.

File metadata

  • Download URL: arc_crawler-0.1.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.6 Windows/11

File hashes

Hashes for arc_crawler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b559006c66d25a6eed25cfb42e35488539c1d23e121f79963e3eee077a02628
MD5 2bc6be6e85bfc830febbba314ad66090
BLAKE2b-256 5ba38fddfb76ca3a00933707da360a43ba445814adf921d6f68e9b04412325df

See more details on using hashes here.

File details

Details for the file arc_crawler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: arc_crawler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.6 Windows/11

File hashes

Hashes for arc_crawler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9eba95de2a2161727ed2d9902a0d840de966730f7aed0f6358896fb353e46c6b
MD5 c4f3d8d57f8f150e60e1471797919912
BLAKE2b-256 ba1746dd39a6793c06a9096e00e9288a0aa71e247c73577334d4a4764c45493f

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