Complete API reference for CrawlX 2.0.
The main crawler class that orchestrates all crawling operations.
new CrawlX(options?: DeepPartial<CrawlerOptions>)Crawl a single URL.
Parameters:
url- The URL to crawloptions- Optional task configuration
Returns: Promise resolving to TaskResult
Example:
const crawler = new CrawlX();
const result = await crawler.crawl('https://example.com', {
parse: { title: 'title' }
});Crawl multiple URLs concurrently.
Parameters:
urls- Array of URLs to crawloptions- Optional task configuration
Returns: Promise resolving to array of TaskResults
Get current crawler statistics.
Returns: Object containing crawler statistics
Get the current configuration instance.
Returns: Config instance
Update crawler configuration at runtime.
Parameters:
updates- Configuration updates to apply
Add a custom plugin to the crawler.
Parameters:
plugin- Plugin instance to add
Remove a plugin by name.
Parameters:
name- Name of the plugin to remove
Returns: True if plugin was removed, false if not found
Destroy the crawler and clean up resources.
The CrawlX class extends EventEmitter and emits the following events:
crawl-start- Emitted when crawling startscrawl-complete- Emitted when crawling completescrawl-error- Emitted when crawling failstask-queued- Emitted when a task is queuedtask-start- Emitted when a task startstask-complete- Emitted when a task completestask-error- Emitted when a task failsurl-discovered- Emitted when a new URL is discovereddata-extracted- Emitted when data is extracted
CSS selector-based parser with filter support.
new Parser(options?: ParserOptions)Parse HTML using the provided rule.
Parameters:
html- HTML string or Cheerio instancerule- Parse rule definition
Returns: Parsed data
Add a custom filter function.
Parameters:
name- Filter namefilter- Filter function
Get all available filters.
Returns: Object containing all filters
HTTP client with multiple modes and Cheerio integration.
Create an HTTP client instance.
Parameters:
mode- Client mode ('lightweight' or 'high-performance')options- Client configuration options
Returns: HttpClient instance
Make an HTTP request.
Make an HTTP request with automatic Cheerio parsing.
Get client statistics.
Destroy the client and clean up resources.
Create a basic crawler instance.
Create a lightweight crawler optimized for simple tasks.
Create a high-performance crawler for large-scale operations.
Create a scraper optimized for data extraction.
Create a spider for following links and discovering content.
Create a monitor for checking website changes.
Create a validator for checking link health.
quickCrawl(url: string, parseRule?: any, options?: DeepPartial<CrawlerOptions>): Promise<TaskResult>
Quick one-off crawling function.
batchCrawl(urls: string[], parseRule?: any, options?: DeepPartial<CrawlerOptions>): Promise<TaskResult[]>
Batch crawl multiple URLs.
Configuration management with validation and environment variable support.
Get configuration value by path.
Set configuration value.
Check if configuration path exists.
Validate configuration against schema.
Factory for creating configuration instances.
Create configuration with various sources.
Create lightweight configuration.
Create high-performance configuration.
Pre-configured crawler instances for common use cases.
ConfigPresets.development()- Development presetConfigPresets.production()- Production presetConfigPresets.testing()- Testing presetConfigPresets.scraping()- Scraping preset
Handles data extraction and parsing.
Handles link following and discovery.
Handles automatic retry with backoff.
Handles request delays and politeness.
Handles URL deduplication.
Handles advanced rate limiting.
interface PluginInterface {
name: string;
version: string;
priority: number;
// Lifecycle hooks
onInit?(): Promise<void>;
onDestroy?(): Promise<void>;
// Task hooks
onTaskCreate?(task: TaskOptions): Promise<TaskOptions>;
onTaskStart?(task: TaskOptions): Promise<void>;
onTaskComplete?(result: TaskResult): Promise<TaskResult>;
onTaskError?(error: Error, task: TaskOptions): Promise<void>;
// HTTP hooks
onRequest?(request: HttpRequest): Promise<HttpRequest>;
onResponse?(response: HttpResponse): Promise<HttpResponse>;
}Structured logging with multiple transports.
Error handling and recovery.
URL manipulation utilities.
Configuration management utilities.
interface CrawlerOptions {
mode?: CrawlerMode;
concurrency?: number;
timeout?: number;
maxRetries?: number;
userAgent?: string;
headers?: Record<string, string>;
// ... more options
}
interface TaskOptions {
url: string;
method?: string;
headers?: Record<string, string>;
body?: any;
parse?: ParseRule;
follow?: FollowRule;
// ... more options
}
interface TaskResult {
task: TaskOptions;
response: HttpResponse;
parsed?: any;
followed?: TaskOptions[];
metadata?: Record<string, any>;
}type ParseRule =
| string // Simple selector
| string[] // Array selector
| ParseRuleObject // Object with nested rules
| ParseRuleFunction; // Custom function
interface ParseRuleObject {
_scope?: string; // Scope selector
[key: string]: ParseRule; // Nested rules
}For complete type definitions, see the types documentation.