# Enhanced Deep Content Crawler (`assertive_analogy/advanced-crawler`) Actor

A fast, Python-powered web crawler with smart content extraction, JS support, metadata capture, and duplicate detection. Ideal for SEO, content migration, and e-commerce scraping. Reliable, scalable, and easy to customize.

- **URL**: https://apify.com/assertive_analogy/advanced-crawler.md
- **Developed by:** [Gideon Nesh](https://apify.com/assertive_analogy) (community)
- **Categories:** Developer tools, SEO tools, E-commerce
- **Features:** Full permissions
- **Stats:** 32 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: 1.00 out of 5 stars

## Pricing

$10.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### Enhanced Deep Content Crawler

A powerful, production-ready web crawler for comprehensive content extraction built with modern Python technologies. This enhanced crawler combines the efficiency of [Crawlee for Python](https://crawlee.dev/python) with advanced content extraction capabilities, intelligent duplicate detection, and robust error handling.

#### 🚀 Key Features

- **Dual Crawling Modes**: Choose between Playwright (JavaScript support) or HTTP-only crawling for optimal performance
- **Smart Content Extraction**: Automatic main content detection with fallback strategies
- **Comprehensive Metadata**: Extracts titles, descriptions, Open Graph data, Twitter Cards, and JSON-LD structured data
- **Duplicate Detection**: Content-based deduplication using hashing algorithms
- **Advanced Link Discovery**: Intelligent internal link extraction with domain validation
- **Real-time Statistics**: Live progress tracking with performance metrics
- **Robust Error Handling**: Retry mechanisms with exponential backoff
- **Flexible Configuration**: Extensive customization options via input schema

### Included features

- **[Apify SDK](https://docs.apify.com/sdk/python/)** - a toolkit for building Apify [Actors](https://apify.com/actors) in Python.
- **[Crawlee for Python](https://crawlee.dev/python/)** - a web scraping and browser automation library.
- **[Input schema](https://docs.apify.com/platform/actors/development/input-schema)** - define and validate a schema for your Actor's input.
- **[Request queue](https://crawlee.dev/python/api/class/RequestQueue)** - manage the URLs you want to scrape in a queue.
- **[Dataset](https://crawlee.dev/python/api/class/Dataset)** - store and access structured data extracted from web pages.
- **[Beautiful Soup](https://pypi.org/project/beautifulsoup4/)** - a library for pulling data out of HTML and XML files.
- **[Playwright](https://playwright.dev/python/)** - modern browser automation for JavaScript-heavy sites.

#### 📊 Data Extraction Capabilities

The enhanced crawler extracts comprehensive data from each page:

##### Basic Information

- **URL**: Complete page URL with timestamp
- **Title**: Page title from `<title>` tag
- **Description**: Meta description and other metadata
- **Word Count**: Total words in main content
- **Page Size**: HTML document size in bytes

##### Advanced Metadata

- **Open Graph Data**: Complete OG tags for social sharing
- **Twitter Card Data**: Twitter-specific metadata
- **Structured Data**: JSON-LD schemas for rich snippets
- **Canonical URLs**: Preferred page URLs
- **Author Information**: When available in meta tags

##### Content Analysis

- **Main Content**: Intelligently extracted article/page content
- **Custom Content**: User-defined CSS selector extraction
- **Content Hash**: For duplicate detection
- **Internal Links**: All same-domain links with metadata
- **Images**: Up to 10 images with alt text and metadata

#### ⚡ Performance Features

- **Dual Mode Operation**:
  - **Browser Mode (Playwright)**: Full JavaScript support, perfect for SPAs
  - **HTTP Mode**: Lightning-fast for static content
- **Concurrent Processing**: Asynchronous crawling with proper queue management
- **Smart Deduplication**: Avoids crawling identical content
- **Progress Tracking**: Real-time statistics and performance metrics
- **Memory Efficient**: Optimized for large-scale crawling

#### 🛡️ Reliability & Error Handling

- **Retry Logic**: Configurable retry attempts with exponential backoff
- **Timeout Management**: Customizable request timeouts
- **Error Categorization**: Detailed error logging and reporting
- **Graceful Degradation**: Continues crawling despite individual page failures
- **URL Validation**: Prevents crawling invalid or dangerous URLs

### Resources

- [Video introduction to Python SDK](https://www.youtube.com/watch?v=C8DmvJQS3jk)
- [Webinar introducing to Crawlee for Python](https://www.youtube.com/live/ip8Ii0eLfRY)
- [Apify Python SDK documentation](https://docs.apify.com/sdk/python/)
- [Crawlee for Python documentation](https://crawlee.dev/python/docs/quick-start)
- [Python tutorials in Academy](https://docs.apify.com/academy/python)
- [Integration with Make, GitHub, Zapier, Google Drive, and other apps](https://apify.com/integrations)
- [Video guide on getting scraped data using Apify API](https://www.youtube.com/watch?v=ViYYDHSBAKM)

### 🛠️ Configuration Options

#### Basic Configuration

```json
{
  "baseUrl": "https://example.com",
  "maxPages": 100,
  "maxDepth": 3
}
```

#### Advanced Configuration

```json
{
  "baseUrl": "https://example.com",
  "maxPages": 500,
  "maxDepth": 4,
  "contentSelector": "article, .post-content, .entry-content",
  "excludePatterns": [
    ".*\\.pdf$",
    "/admin/.*",
    ".*\\?.*utm_.*"
  ],
  "useBrowser": true,
  "maxRetries": 5,
  "requestTimeout": 45000
}
```

#### Configuration Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `baseUrl` | string | required | Starting URL for crawling |
| `maxPages` | integer | 100 | Maximum pages to crawl (1-1000) |
| `maxDepth` | integer | 3 | Maximum link depth to follow (1-10) |
| `contentSelector` | string | "body" | CSS selector for content extraction |
| `excludePatterns` | array | \[] | Regex patterns to exclude URLs |
| `useBrowser` | boolean | true | Enable JavaScript with Playwright |
| `maxRetries` | integer | 3 | Retry attempts for failed requests |
| `requestTimeout` | integer | 30000 | Request timeout in milliseconds |

### 🚀 Usage Examples

#### E-commerce Site Crawling

```json
{
  "baseUrl": "https://shop.example.com",
  "maxPages": 200,
  "contentSelector": ".product-description, .product-specs",
  "excludePatterns": [
    "/cart.*",
    "/checkout.*",
    "/account.*"
  ]
}
```

#### News Site Crawling

```json
{
  "baseUrl": "https://news.example.com",
  "maxPages": 1000,
  "maxDepth": 2,
  "contentSelector": "article, .post-content",
  "useBrowser": false,
  "excludePatterns": [
    "/tag/.*",
    "/author/.*",
    ".*\\?.*utm_.*"
  ]
}
```

#### Documentation Site Crawling

```json
{
  "baseUrl": "https://docs.example.com",
  "maxPages": 300,
  "contentSelector": ".markdown-body, .content",
  "excludePatterns": [
    ".*\\.pdf$",
    ".*\\.zip$"
  ]
}
```

### 📊 Output Data Structure

Each crawled page produces a comprehensive data object:

```json
{
  "url": "https://example.com/page",
  "crawled_at": "2024-01-15T10:30:00Z",
  "content_hash": "a1b2c3d4e5f6",
  "metadata": {
    "title": "Page Title",
    "description": "Page description",
    "keywords": "keyword1, keyword2",
    "author": "Author Name",
    "canonical_url": "https://example.com/canonical",
    "og_data": {
      "title": "Social Title",
      "description": "Social Description",
      "image": "https://example.com/image.jpg"
    },
    "structured_data": [
      {
        "@type": "Article",
        "headline": "Article Title"
      }
    ]
  },
  "main_content": "Extracted main content text...",
  "specific_content": "Content from custom selector...",
  "images": [
    {
      "src": "https://example.com/image.jpg",
      "alt": "Image description",
      "title": "Image title",
      "width": "800",
      "height": "600"
    }
  ],
  "internal_links": [
    {
      "url": "https://example.com/linked-page",
      "text": "Link text",
      "title": "Link title"
    }
  ],
  "word_count": 1250,
  "page_size": 45678,
  "load_time": 1.23
}
```

- A short guide on how to build web scrapers using code templates:

[web scraper template](https://www.youtube.com/watch?v=u-i-Korzf8w)

### Getting started

For complete information [see this article](https://docs.apify.com/platform/actors/development#build-actor-at-apify-console). In short, you will:

1. Build the Actor
2. Run the Actor

### Pull the Actor for local development

If you would like to develop locally, you can pull the existing Actor from Apify console using Apify CLI:

1. Install `apify-cli`

   **Using Homebrew**

   ```bash
   brew install apify-cli
   ```

   **Using NPM**

   ```bash
   npm -g install apify-cli
   ```

2. Pull the Actor by its unique `<ActorId>`, which is one of the following:

   - unique name of the Actor to pull (e.g. "apify/hello-world")
   - or ID of the Actor to pull (e.g. "E2jjCZBezvAZnX8Rb")

   You can find both by clicking on the Actor title at the top of the page, which will open a modal containing both Actor unique name and Actor ID.

   This command will copy the Actor into the current directory on your local machine.

   ```bash
   apify pull <ActorId>
   ```

### Documentation reference

To learn more about Apify and Actors, take a look at the following resources:

- [Apify SDK for JavaScript documentation](https://docs.apify.com/sdk/js)
- [Apify SDK for Python documentation](https://docs.apify.com/sdk/python)
- [Apify Platform documentation](https://docs.apify.com/platform)
- [Join our developer community on Discord](https://discord.com/invite/jyEM2PRvMU)

# Actor input Schema

## `baseUrl` (type: `string`):

The starting URL for the crawler

## `maxPages` (type: `integer`):

The maximum number of pages to crawl (max: 1000)

## `maxDepth` (type: `integer`):

The maximum depth of links to follow (max: 10)

## `contentSelector` (type: `string`):

CSS selector for extracting specific content (leave 'body' for automatic detection)

## `excludePatterns` (type: `array`):

Regular expressions to exclude URLs (e.g., \[".*.pdf$", "/admin/.*"])

## `useBrowser` (type: `boolean`):

Enable JavaScript rendering with Playwright (slower but handles dynamic content)

## `maxRetries` (type: `integer`):

Number of retry attempts for failed requests

## `requestTimeout` (type: `integer`):

Timeout for each request in milliseconds

## Actor input object example

```json
{
  "baseUrl": "https://cookcollectivekitchen.com/",
  "maxPages": 100,
  "maxDepth": 3,
  "contentSelector": "body",
  "excludePatterns": [],
  "useBrowser": true,
  "maxRetries": 3,
  "requestTimeout": 30000
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("assertive_analogy/advanced-crawler").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("assertive_analogy/advanced-crawler").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call assertive_analogy/advanced-crawler --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,assertive_analogy/advanced-crawler"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/h8bgqXOcdxCMH3zQq/builds/DVycorfWuQtE2BPQ7/openapi.json
