# Web Scraper and AI processor (`scraping_samurai/web-scraper-and-ai-processor`) Actor

Adaptive AI controller classifies page quality from fast HTTP fetches and selectively triggers headless rendering, then converts raw text into structured JSON from natural-language extraction prompts. Optimizes cost vs. accuracy with AI-guided escalation, retry, and thin/blocked content heuristics.

- **URL**: https://apify.com/scraping_samurai/web-scraper-and-ai-processor.md
- **Developed by:** [Scraping Samurai](https://apify.com/scraping_samurai) (community)
- **Categories:** AI, Automation, Lead generation
- **Stats:** 39 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

from $100.00 / 1,000 actor run starts

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

## Smart Web Scraper & Data Extractor

Extract **structured data** from any set of web pages with ease.\
This Actor crawls your target URLs, handles **blocking** automatically, and uses an **advanced AI-powered extraction engine** to transform messy page text into clean, structured outputs such as JSON.

***

### ✨ Features

- **HTTP-first crawling** → Fast & efficient.
- **Automatic browser fallback** → If pages block bots or require JS rendering, the Actor switches to a full browser for reliable scraping.
- **AI-powered text extraction** → Provide your own natural language instruction (e.g., *“Extract all emails and phone numbers as JSON”*), and the Actor will return structured results.
- **Robust anti-blocking** → Uses concurrency controls, proxy support, and session handling for maximum reliability.
- **Pay-per-event pricing** → You pay only for the work done:
  - Run start
  - Each URL processed via HTTP
  - Each URL escalated to browser

***

### 🚀 Use Cases

- **Lead generation** → Extract contact details (emails, phones, LinkedIn URLs).
- **E-commerce monitoring** → Get product names, prices, SKUs, and stock statuses.
- **News & blogs** → Collect article titles, authors, dates, and summaries.
- **SEO research** → Extract H1s, meta descriptions, canonical URLs.
- **Custom reports** → Pull out exactly what you need with a single instruction.

***

### 🛠️ Input Schema

```jsonc
{
  "urls": [
    "https://apify.com/",
    "https://crawlee.dev/"
  ],
  "extractionInstruction": "Extract the page title and the first H1 as JSON with keys: title, h1."
}
```

**Fields:**

- `urls` *(array, required)* — List of page URLs to scrape.
- `extractionInstruction` *(string, required)* — Describe what to extract in plain language.

> **Note:** Advanced crawling options (concurrency, retries, proxy settings, etc.) are set internally and are not user-configurable.

***

### 📊 Output Example

```jsonc
{
  "url": "https://crawlee.dev/",
  "content": "…extracted plain text from the page…",
  "aiAnswer": {
    "title": "Crawlee",
    "h1": "The web scraping and browser automation library for Node.js"
  },
  "status": "success"
}
```

**Each record contains:**

- `url` — Source page
- `content` — Extracted raw text
- `aiAnswer` — Structured data matching your instruction
- `status` — `success`, `blocked`, or `error`

***

### 💵 Pricing Model

This Actor uses a **pay-per-event pricing** system.\
You only pay for what you actually use:

- **Run start (`run-start`)** → A flat fee charged once at the beginning of each run.
- **URL (HTTP) start (`url-http-start`)** → A fee charged for every URL processed with the fast HTTP crawler.
- **URL (Browser) start (`url-browser-start`)** → A higher fee charged only if the Actor needs to escalate a URL to full browser mode (Playwright).

#### Why this model?

- **Fair** → You don’t pay for unused capacity, only for actual work.
- **Predictable** → Costs scale with the number of pages and whether they need browser fallback.
- **Efficient** → Most pages succeed in fast HTTP mode, so you save money. Browser mode is used only when necessary.

***

#### Example

If you run the Actor with 100 URLs:

- 100 × `url-http-start`
- - 20 × `url-browser-start` (if 20 of them needed browser)
- - 1 × `run-start`

👉 Total = cost of 121 events.

***

### 🔒 Why Choose This Actor?

- Built on **Apify platform** with **Crawlee** under the hood.
- Designed for **scalability and reliability** — from a few URLs to thousands.
- **No brittle CSS selectors** — describe what you want in plain language.
- Handles **dynamic pages, blocking, and captchas** with minimal setup.

***

### 💡 Pro Tips

- Write precise extraction instructions → “Extract product name, price, and availability as JSON with keys: name, price, availability.”
- Use **proxies** for large-scale scraping to avoid rate limits.
- Set a reasonable `minCharsThreshold` to automatically retry thin or blocked pages in browser mode.

***

### 📈 SEO Keywords

Web scraping, data extraction, structured data, AI extractor, JSON extraction, Apify actor, automatic browser fallback, anti-blocking crawler, scrape websites, intelligent scraper, text-to-JSON, scalable web scraping.

***

### ⚡ Get Started Now

1. Add your URLs and extraction instruction.
2. Run the Actor on [Apify](https://apify.com).
3. Get clean, structured data — fast, reliable, and AI-enhanced.

***

Turn **any website into structured data** with one Actor run. Save hours of manual parsing and let the scraper + AI do the heavy lifting.

# Actor input Schema

## `urls` (type: `array`):

List of page URLs to scrape.

## `extractionInstruction` (type: `string`):

Describe exactly what to extract from the page text. For best results, ask for concise JSON in your answer.

## Actor input object example

```json
{
  "urls": [
    "https://apify.com/",
    "https://crawlee.dev/"
  ],
  "extractionInstruction": "Extract the page title and the first H1 as JSON with keys: title, h1."
}
```

# 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 = {
    "urls": [
        "https://apify.com/",
        "https://crawlee.dev/"
    ],
    "extractionInstruction": "Extract the page title and the first H1 as JSON with keys: title, h1."
};

// Run the Actor and wait for it to finish
const run = await client.actor("scraping_samurai/web-scraper-and-ai-processor").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 = {
    "urls": [
        "https://apify.com/",
        "https://crawlee.dev/",
    ],
    "extractionInstruction": "Extract the page title and the first H1 as JSON with keys: title, h1.",
}

# Run the Actor and wait for it to finish
run = client.actor("scraping_samurai/web-scraper-and-ai-processor").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 '{
  "urls": [
    "https://apify.com/",
    "https://crawlee.dev/"
  ],
  "extractionInstruction": "Extract the page title and the first H1 as JSON with keys: title, h1."
}' |
apify call scraping_samurai/web-scraper-and-ai-processor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,scraping_samurai/web-scraper-and-ai-processor"
        }
    }
}
```

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/St3iPZFYISkgTEDDG/builds/qAerePYHUsSZIhUBA/openapi.json
