# Website Content Extractor (`fastidious_drawer/website-content-extractor`) Actor

This extractor lets you extract content from any website with a single or multiple URLs. Use selectors to choose specific sections like the body and exclude elements like headers or navigation. It also extracts images and links, providing data in JSON and DataTable formats for easy processing.

- **URL**: https://apify.com/fastidious_drawer/website-content-extractor.md
- **Developed by:** [fastidious_drawer](https://apify.com/fastidious_drawer) (community)
- **Categories:** Developer tools, Lead generation, Automation
- **Stats:** 165 total users, 0 monthly users, 100.0% runs succeeded, 4 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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 Content Extractor

The Website Content Extractor is a web scraping tool designed to extract text, images, metadata, and links from specified websites using Playwright and Crawlee. It allows users to define target URLs, CSS selectors for content extraction, and exclusion rules.

### Features

- **Extract Text**: Extracts visible text from the website based on CSS selectors.
- **Extract Metadata**: Extracts metadata including canonical URL, title, description, and Open Graph data.
- **Extract Images**: Optionally extract all images from the page.
- **Extract Links**: Optionally extract all links from the page.
- **Exclude Selectors**: Excludes certain page elements (e.g., `header`, `footer`, `nav`) from the extraction.
- **Crawl Multiple Pages**: Crawl and extract content from multiple pages if needed.

### How to Use

### Input

The input is a JSON configuration that specifies the settings for the extraction process.

#### Fields

- `urls` (required): **Array of URLs** — List of website URLs to extract content from.
- `selectors`: **Array of CSS selectors** — Specifies which elements to extract content from.
- `excludeSelectors`: **Array of CSS selectors** — Specifies elements to exclude from extraction (e.g., `header`, `nav`, `footer`).
- `extractImages`: **Boolean** — If set to `true`, images from the page will be extracted.
- `extractLinks`: **Boolean** — If set to `true`, links from the page will be extracted.
- `maxPages`: **Integer** — Limits the number of pages to crawl. Defaults to `1` if not set.

#### Example Input

```json
{
    "urls": [
        "https://example.com"
    ],
    "selectors": [
        "p",
        "h1"
    ],
    "excludeSelectors": [
        "header",
        "footer"
    ],
    "extractImages": true,
    "extractLinks": true,
    "maxPages": 3
}
```

### Output

The output consists of extracted data for each URL, including:

- **Text**: All text content extracted from the specified selectors.
- **Markdown**: Converted Markdown format of the extracted text.
- **Metadata**: Metadata such as canonical URL, title, description, and Open Graph data.
- **Images**: List of image URLs extracted from the page (if enabled).
- **Links**: List of all links found on the page (if enabled).
- **Crawl Information**: Includes the URL, loading time, HTTP status code, and crawl depth.

#### Example Output

```json
{
    "url": "https://example.com",
    "crawl": {
        "loadedUrl": "https://example.com",
        "loadedTime": "2025-03-10T10:00:00Z",
        "depth": 0,
        "httpStatusCode": 200
    },
    "text": "Extracted text content...",
    "markdown": "**Extracted Text:**\n\nExtracted text content...",
    "metadata": {
        "canonicalUrl": "https://example.com/canonical",
        "title": "Page Title",
        "description": "Page description here",
        "openGraph": [
            { "property": "og:title", "content": "Page Title" },
            { "property": "og:description", "content": "Page description here" }
        ],
        "jsonLd": []
    },
    "images": ["https://example.com/image1.jpg", "https://example.com/image2.jpg"],
    "links": ["https://example.com/page1", "https://example.com/page2"]
}
```

### Notes

- **CSS Selectors**: Use valid CSS selectors to extract the specific content you need from the web pages.
- **Limitations**: Depending on the website, some content may be loaded dynamically via JavaScript. In such cases, make sure to enable Playwright's capabilities to handle dynamic content.
- **Crawl Depth**: Set `maxPages` to crawl more pages from the same domain, but be mindful of rate limits and page load times.

# Actor input Schema

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

The website URL to extract content from.

## `selectors` (type: `array`):

List of CSS selectors to extract specific content.

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

List of CSS selectors to exclude from extraction (e.g., nav, header, footer).

## `extractImages` (type: `boolean`):

Whether to extract images from the website.

## `extractLinks` (type: `boolean`):

Whether to extract links from the website.

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

Limits the number of pages to extract content from.

## Actor input object example

```json
{
  "urls": [
    "https://apify.com"
  ],
  "selectors": [],
  "excludeSelectors": [],
  "extractImages": false,
  "extractLinks": false,
  "maxPages": 10
}
```

# 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("fastidious_drawer/website-content-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("fastidious_drawer/website-content-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 '{}' |
apify call fastidious_drawer/website-content-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fastidious_drawer/website-content-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/GLSalPVswuKecj1qz/builds/6NdOPWT6oreBFCrU4/openapi.json
