# Webpage Clean Text (`eichan/webpage-clean-text`) Actor

- **URL**: https://apify.com/eichan/webpage-clean-text.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.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

## Webpage Clean Text — LLM-Ready Plain Text & Markdown

**Slug:** `webpage-clean-text`\
**Category:** AI / AI data preparation (not a chatbot)\
**Apify Store categories to select when publishing:** `AI`, `DEVELOPER_TOOLS` (2 of 3 available). These are publishing choices, **not** automatic settings in `actor.json`.\
**Suggested pricing:** **per run** (one URL produces one dataset item). Configure pricing separately in Apify Console; this repository does not set fees.

### What it does

Fetches **one** public, static HTML webpage (or a plain-text URL) and returns its readable text plus simple Markdown. Useful for retrieval-augmented generation (RAG) preparation, search indexing, prompt preparation, and data-cleaning workflows. It **does not** generate an AI summary, rank importance, or make semantic judgments.

### How the method works

1. Validate that the URL is HTTP(S) and resolves to public internet IP addresses. Check redirects too.
2. Download at most **1 MB** of HTML/text using `urllib.request` with a 15-second network timeout.
3. Parse static HTML with the standard-library `html.parser` and decode HTML entities.
4. Exclude common boilerplate tags (`script`, `style`, `nav`, `header`, `footer`, `aside`, `form`, etc.). If a `<main>` or `<article>` region contains text, favor that region; otherwise use the remaining page text.
5. Emit block-separated **plain text** and **basic Markdown** (`#` headings and `-` list items). `word_count` counts whitespace-separated tokens, not linguistic words.

No external LLM, browser, JavaScript renderer, login, or third-party Python package is used. The standard **Apify platform token provided to an Actor run** is used only to read the run's input and publish output through the Apify storage API; customers do not supply a key.

### Input example

One URL only:

```json
{
  "url": "https://example.com/"
}
```

### Output example

One item is appended to the **default dataset**. The values below are illustrative; live website content can change:

```json
{
  "url": "https://example.com/",
  "title": "Example Domain",
  "text": "Example Domain\n\nThis domain is for use in documentation examples.",
  "markdown": "# Example Domain\n\nThis domain is for use in documentation examples.",
  "word_count": 10
}
```

| Field | Type | Meaning |
| --- | --- | --- |
| `url` | string | Final URL after redirects |
| `title` | string | HTML `<title>`, or empty string |
| `text` | string | Extracted text separated by blank lines |
| `markdown` | string | Basic Markdown, not full HTML-to-Markdown fidelity |
| `word_count` | integer | Whitespace-separated word count in `text` |

### Who this is for

Developers feeding public information into AI search, RAG ingestion, indexes, or data transformation pipelines without running an LLM.

### Limitations and safety

- **Static HTML only.** JavaScript-rendered content, SPA application views, PDF, paywalls, authenticated pages, cookie consent workflows, and blocked sources are not supported.
- Main/article selection is a **simple HTML tag heuristic**. It can omit important content or include ads and boilerplate. It does not understand page meaning.
- Markdown is intentionally basic. HTML tables, links, inline emphasis, image descriptions, page layout, and code formatting are not preserved faithfully.
- Whitespace is normalized. Complex HTML, malformed markup, and non-UTF-8 pages without a declared charset may yield imperfect text.
- Only public HTTP(S) pages on standard ports (80/443) are accepted; private and loopback destinations are rejected, including on redirects. DNS validation is a protective check, **not a security guarantee against DNS rebinding**. Never use this as a privileged intranet fetcher.
- Honor website access policies, copyright, and applicable law. A public URL does not guarantee permission to reuse content.
- One failed fetch returns a plain-language `ERROR:` in the run log, exits nonzero, and does **not** create a misleading success row. No Python traceback is shown.

### Running locally (no Apify SDK)

From the actor's root folder, create `storage/key_value_stores/default/INPUT.json` with the input example above. Run:

```bash
python src/main.py
```

The result is written to `storage/datasets/default/000000001.json` (or the next available numbered JSON file). Clear `storage/` between independent test runs if you do not want accumulated results.

### Running on Apify

Build from the included `Dockerfile` and use the form generated from `input_schema.json`. The Actor reads input from its **default key-value store** using the Apify API and writes one JSON item to its **default dataset** using the Apify API. This is necessary because **local JSON files alone do not publish dataset items to the Apify cloud**. `APIFY_IS_AT_HOME`, `APIFY_TOKEN`, and the `ACTOR_DEFAULT_*` environment variables are provided by Apify; no manual API token configuration is needed.

There are no Python dependencies to install; `requirements.txt` deliberately contains no packages.

# Actor input Schema

## `url` (type: `string`):

One publicly reachable HTTP or HTTPS URL (no login, private IP address, or custom port).

## Actor input object example

```json
{
  "url": "https://example.com/"
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the Actor's result items

# 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 = {
    "url": "https://example.com/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/webpage-clean-text").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 = { "url": "https://example.com/" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/webpage-clean-text").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 '{
  "url": "https://example.com/"
}' |
apify call eichan/webpage-clean-text --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/webpage-clean-text"
        }
    }
}
```

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/1JgimtbH0eZDuarkM/builds/OnCHjESyvHbvdeIA7/openapi.json
