Skip to main content
The CrawlResult class represents the complete result from a spider run, including scraped items, statistics, and pause state.

Class Definition

Attributes

CrawlStats
required
Detailed statistics about the crawl (requests, items, timing, etc.).
ItemList
required
List of scraped items with export capabilities.
bool
default:"False"
Whether the crawl was paused (True) or completed normally (False).

Properties

completed

Returns True if the crawl completed normally (not paused). Returns: not self.paused

Special Methods

Length

Returns the number of scraped items. Example:

Iteration

Iterate over scraped items. Example:

ItemList

The items attribute is an ItemList - a list subclass with export methods.

to_json

Export items to a JSON file.
str | Path
required
Path to the output file.
bool
default:"False"
Pretty-print with 2-space indentation (slightly slower).
Example:

to_jsonl

Export items as JSON Lines (one JSON object per line).
str | Path
required
Path to the output file.
Example:

CrawlStats

The stats attribute contains detailed crawl metrics.

Attributes

int
default:"0"
Total number of successful requests made.
int
default:"0"
Maximum concurrent requests setting.
int
default:"0"
Maximum concurrent requests per domain setting.
int
default:"0"
Number of failed requests (exceptions during fetch).
int
default:"0"
Number of requests filtered due to allowed_domains.
int
default:"0"
Number of requests detected as blocked.
int
default:"0"
Total bytes downloaded.
int
default:"0"
Number of items successfully scraped.
int
default:"0"
Number of items dropped by on_scraped_item().
float
default:"0.0"
Timestamp when crawl started.
float
default:"0.0"
Timestamp when crawl ended.
float
default:"0.0"
Download delay setting.
Dict
default:"{}"
User-defined custom statistics.
Dict
default:"{}"
Count of responses by status code (e.g., {"status_200": 42, "status_404": 3}).
Dict
default:"{}"
Bytes downloaded per domain.
Dict
default:"{}"
Requests made per session ID.
List[str | Dict | Tuple]
default:"[]"
List of proxies used during the crawl.
Dict
default:"{}"
Count of log messages by level (debug, info, warning, error, critical).

Properties

elapsed_seconds

Total crawl duration in seconds. Returns: end_time - start_time

requests_per_second

Average request rate. Returns: requests_count / elapsed_seconds (or 0.0 if elapsed_seconds == 0)

Methods

to_dict

Convert statistics to a dictionary. Returns: Dictionary with formatted statistics Example:

Usage Examples

Basic Usage

Export Results

Iterate Items

Detailed Statistics

Handle Paused Crawls

Custom Statistics

Performance Analysis

Logging Analysis

Complete Example

See Also

  • Spider - Running spiders and getting results
  • CrawlerEngine - Understanding statistics collection