# Website Text Extractor - Webpage Content to Ordered Text Blocks (`smart-digital/website-content-text-extractor`) Actor

Extract the visible text of any web page as numbered blocks in DOM order, each carrying its HTML tag. One JSON item per URL: page title, every text block, per-page counts. Batch several URLs in one run, optionally drop headers, footers and cookie banners. For translation, migration and copy audits.

- **URL**: https://apify.com/smart-digital/website-content-text-extractor.md
- **Developed by:** [My Smart Digital](https://apify.com/smart-digital) (community)
- **Categories:** Developer tools, AI, Automation
- **Features:** Limited permissions
- **Stats:** 92 total users, 2 monthly users, 100.0% runs succeeded, 2 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $10.00 / 1,000 pages

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

## Website Text Extractor

Apify Actor for extracting visible text content from websites as structured JSON blocks.

### Description

Extract clean, visible text from websites as structured blocks. Perfect for content migration, translation workflows, and data analysis. This actor extracts text content that is actually visible to users, with options to exclude headers, footers, cookies, and extract form content.

### Features

✅ **Multi-URL Batch Processing**: Process multiple URLs in a single run\
✅ **Viewport Presets**: Choose between Desktop (1920x1080), Mobile (375x667), Tablet (768x1024), or custom dimensions\
✅ **Header/Footer/Cookie Exclusion**: Compatible with WordPress, Shopify, Webflow, Drupal, Joomla and most CMS platforms\
✅ **Form Content Extraction**: Optional extraction of form content (labels, placeholders, values, dropdown options)\
✅ **DOM Order Preservation**: Text blocks extracted in the order they appear on the page\
✅ **Code Filtering**: Automatically filters out JavaScript, CSS, and code snippets\
✅ **Deduplication**: Removes duplicate text blocks\
✅ **Configurable Selectors**: Customize which elements to include/exclude\
✅ **Clean JSON Output**: Structured output perfect for content analysis, translation, and data migration

### Input

```json
{
  "startUrls": [
    "https://example.com",
    "https://example.com/about",
    "https://example.com/contact"
  ],
  "viewportType": "desktop",
  "viewportWidth": 1920,
  "viewportHeight": 1080,
  "excludeHeader": false,
  "excludeFooter": false,
  "excludeCookies": false,
  "excludeSelectors": [],
  "includeSelectors": [],
  "minTextLength": 3,
  "deduplicate": true,
  "waitForSelector": "",
  "waitTimeout": 30000,
  "removeEmptyBlocks": true,
  "extractForms": false
}
```

#### Parameters

- **startUrl** (optional): Single URL to extract text from (useful for quick tests). Leave empty if you only use startUrls
- **startUrls** (optional): List of additional URLs to process in bulk in a single run. Duplicates and empty lines are ignored. Use this field to process multiple pages in one execution
- **viewportType** (optional, default: "desktop"): Choose a predefined viewport size (desktop, mobile, tablet) or use custom dimensions
- **viewportWidth** (optional, default: 1920): Custom viewport width in pixels (only used when viewportType is "custom")
- **viewportHeight** (optional, default: 1080): Custom viewport height in pixels (only used when viewportType is "custom")
- **excludeHeader** (optional, default: false): Exclude header and navigation elements. Compatible with WordPress, Shopify, Webflow, Drupal, Joomla and most CMS platforms. If this doesn't work for your site, use Exclude Selectors manually
- **excludeFooter** (optional, default: false): Exclude footer elements. Compatible with WordPress, Shopify, Webflow, Drupal, Joomla and most CMS platforms. If this doesn't work for your site, use Exclude Selectors manually
- **excludeCookies** (optional, default: false): Exclude cookie consent banners and GDPR notices. Compatible with Cookiebot, OneTrust, Iubenda and most cookie consent platforms
- **extractForms** (optional, default: false): Extract form content (labels, placeholders, values). When disabled, form elements (form, input, textarea, select, label) are excluded from extraction. When enabled, form content is extracted including labels, placeholders, and input values. Each form field and dropdown option is extracted as a separate block
- **excludeSelectors** (optional, default: \[]): Additional CSS selectors for custom elements to exclude. Use this if Exclude Header/Footer/Cookies options don't work for your site structure
- **includeSelectors** (optional): CSS selectors to specifically include. If empty, all visible text is extracted
- **minTextLength** (optional, default: 3): Minimum character length for text blocks
- **deduplicate** (optional, default: true): Remove duplicate text blocks
- **waitForSelector** (optional): CSS selector to wait for before extraction
- **waitTimeout** (optional, default: 30000): Timeout in milliseconds for waiting for selector
- **removeEmptyBlocks** (optional, default: true): Remove empty or whitespace-only text blocks

### Output

The actor returns a JSON object with the following structure:

```json
{
  "url": "https://example.com",
  "title": "Page Title",
  "viewport": {
    "width": 1920,
    "height": 1080
  },
  "textBlocks": [
    {
      "id": "block-1",
      "text": "First visible text block",
      "order": 1,
      "tagName": "h1",
      "selector": null
    },
    {
      "id": "block-2",
      "text": "Second text block",
      "order": 2,
      "tagName": "p",
      "selector": null
    }
  ],
  "statistics": {
    "totalBlocks": 25,
    "totalCharacters": 5432,
    "uniqueBlocks": 23,
    "excludedElements": 8
  }
}
```

#### Output Fields

- **url**: The URL that was processed
- **title**: Page title
- **viewport**: Viewport dimensions used
- **textBlocks**: Array of extracted text blocks, each with:
  - **id**: Unique identifier (block-1, block-2, etc.)
  - **text**: The extracted text content
  - **order**: Order of appearance (1, 2, 3, etc.)
  - **tagName**: HTML tag name (h1, p, li, etc.)
  - **selector**: CSS selector if extracted from specific selector
- **statistics**: Summary statistics

### Pricing

This Actor is pay per event. Two events are charged, at the prices shown on this page:

- **Actor Start** — charged once per run, one event per gigabyte of memory allocated (minimum one).
- **PAGE_EXTRACTED** — charged once per page whose text was actually extracted and returned. A URL that could not be loaded, or that its site answered with the page of its anti-bot protection instead of its own (a Cloudflare challenge, for example), returns no item and is not charged.

### Use Cases

- **Content Translation**: Extract clean text blocks for translation workflows
- **Content Analysis**: Analyze visible content without navigation/header/footer noise
- **SEO Content Extraction**: Get only the main content for SEO analysis
- **Content Migration**: Extract content for migration to new platforms
- **Form Data Extraction**: Extract form labels, placeholders, and dropdown options for documentation or analysis

### Header and Footer Exclusion

By default, **nothing is excluded** - all visible text is extracted. You can optionally exclude headers and/or footers using the `excludeHeader` and `excludeFooter` options.

When enabled, these options use universal selectors compatible with:

- **WordPress**: `.site-header`, `.elementor-location-header`, `.wp-block-navigation`, etc.
- **Shopify**: `.shopify-section-header`, `.shopify-section-footer`, etc.
- **Webflow**: `[class*='header']`, `[id*='header']`, etc.
- **Drupal**: `.region-header`, `.region-footer`, etc.
- **Joomla**: `.header`, `.footer`, `.moduletable-menu`, etc.
- **Generic**: `header`, `footer`, `nav`, `[role='banner']`, `[role='contentinfo']`, etc.

If these options don't work for your specific site structure, you can use the `excludeSelectors` parameter to manually specify CSS selectors.

### Technical Details

- Uses **Playwright** for rendering with configurable viewport sizes
- Waits for `networkidle` to ensure all content is loaded
- Automatically scrolls pages to load lazy-loaded content
- Works within the run timeout: with a short timeout (30 to 60 seconds is common for AI agents), each page is opened in a fast mode where images, videos, fonts and embedded frames, which never carry the page's text, are not downloaded; the waits are shortened, and the page is frozen as it stands before its text is read. A run shorter than two minutes opens all its pages this way, one at a time, and with several URLs each page waits only its share of the time left, so one slow page cannot take the whole run. The run ends on its own just before its timeout, with the pages already extracted: it succeeds when it delivered at least one page, and fails with a message saying so when the timeout left no time to extract any, instead of being cut off without a result
- A URL that cannot be loaded (an address that does not answer) or that its site turns away is named in the run's status message with the reason, and nothing is charged for it. A site turns a request away when it refuses automated requests (HTTP 401, 403 or 429), or when its anti-bot protection answers with its own page instead of the site's, whatever the status code: a Cloudflare challenge, the error page of Akamai's edge, an AWS WAF challenge, a DataDome or Imperva block. The text of such a page describes the protection, not the site, so it is neither returned nor charged. The extractor does not try to get past a protection
- Checks element visibility using computed styles and layout boxes (`getClientRects()`)
- Filters out elements with `display: none`, `visibility: hidden`, `opacity: 0`
- Filters out JavaScript, CSS, and code snippets automatically
- Reads the whole rendered page, not only the part shown in the viewport
- Deduplicates text blocks by normalized (lowercase) content
- Maintains DOM order for accurate content structure

# Actor input Schema

## `startUrl` (type: `string`):

Single URL to extract text from (useful for quick tests). You can also use startUrls for multi-page runs. Leave empty if you only use startUrls.

## `startUrls` (type: `array`):

Additional URLs to process in bulk in a single run (one URL per line). Duplicates and empty lines are ignored. Use this field to extract several pages in one execution.

## `viewportType` (type: `string`):

Choose a predefined viewport size or use custom dimensions

## `viewportWidth` (type: `integer`):

Custom viewport width in pixels (only used when Viewport Type is 'custom')

## `viewportHeight` (type: `integer`):

Custom viewport height in pixels (only used when Viewport Type is 'custom')

## `excludeHeader` (type: `boolean`):

Exclude header and navigation elements. Compatible with WordPress, Shopify, Webflow, Drupal, Joomla and most CMS platforms. If this doesn't work for your site, use Exclude Selectors manually.

## `excludeFooter` (type: `boolean`):

Exclude footer elements. Compatible with WordPress, Shopify, Webflow, Drupal, Joomla and most CMS platforms. If this doesn't work for your site, use Exclude Selectors manually.

## `excludeCookies` (type: `boolean`):

Exclude cookie consent banners and GDPR notices. Compatible with Cookiebot, OneTrust, Iubenda and most cookie consent platforms.

## `extractForms` (type: `boolean`):

Extract form content (labels, placeholders, values). When disabled, form elements are excluded from extraction. When enabled, form content is extracted including labels, placeholders, and input values.

## `excludeSelectors` (type: `array`):

Additional CSS selectors for custom elements to exclude. Use this if Exclude Header/Footer options don't work for your site structure.

## `includeSelectors` (type: `array`):

CSS selectors to specifically include. If empty, all visible text is extracted.

## `minTextLength` (type: `integer`):

Minimum character length for text blocks to be included (default: 3)

## `deduplicate` (type: `boolean`):

Remove duplicate text blocks (default: true)

## `waitForSelector` (type: `string`):

Optional CSS selector to wait for before extraction (e.g., '.main-content')

## `waitTimeout` (type: `integer`):

Timeout in milliseconds for waiting for selector (default: 30000)

## `removeEmptyBlocks` (type: `boolean`):

Remove empty or whitespace-only text blocks (default: true)

## Actor input object example

```json
{
  "startUrl": "https://example.com",
  "startUrls": [],
  "viewportType": "desktop",
  "viewportWidth": 1920,
  "viewportHeight": 1080,
  "excludeHeader": false,
  "excludeFooter": false,
  "excludeCookies": false,
  "extractForms": false,
  "excludeSelectors": [],
  "includeSelectors": [],
  "minTextLength": 3,
  "deduplicate": true,
  "waitForSelector": "",
  "waitTimeout": 30000,
  "removeEmptyBlocks": true
}
```

# 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 = {
    "startUrl": "https://example.com",
    "startUrls": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("smart-digital/website-content-text-extractor").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 = {
    "startUrl": "https://example.com",
    "startUrls": [],
}

# Run the Actor and wait for it to finish
run = client.actor("smart-digital/website-content-text-extractor").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 '{
  "startUrl": "https://example.com",
  "startUrls": []
}' |
apify call smart-digital/website-content-text-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,smart-digital/website-content-text-extractor"
        }
    }
}
```

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/asSVNi4XOAPJEMbIY/builds/8z5Rgn0deyKp9U1Az/openapi.json
