# Html to Markdown Converter (`antonio_espresso/html-to-markdown-converter`) Actor

Crawl a target URL and convert its HTML content into clean, structured Markdown with optional heading-based chunking.

- **URL**: https://apify.com/antonio_espresso/html-to-markdown-converter.md
- **Developed by:** [Antonio Blago](https://apify.com/antonio_espresso) (community)
- **Categories:** Integrations, Automation, Agents
- **Stats:** 39 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$10.00 / 1,000 conversions

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

#### Html to Markdown Converter

Convert HTML pages to clean, structured Markdown with optional heading-level chunking.

This Apify actor crawls one or more URLs, extracts HTML content and converts it into readable Markdown. It supports both full-document conversion and heading-based section chunking (`h1–h6`).

***

### 🚀 Features

- 🕷️ Crawl any public website
- 🪄 Convert HTML to GitHub-style Markdown
- 🧩 Automatically chunk content by heading
- 🧼 Cleans up temporary crawl artifacts
- 🐞 Logs crawl/parsing issues to Apify logs

***

### 📥 Input Example

```json
{
  "urls": ["https://apify.com"],
  "output_format": "json",
  "debug": false
}
```

| Field           | Type    | Description                         |
| --------------- | ------- | ----------------------------------- |
| `urls`          | array   | List of URLs to crawl               |
| `output_format` | string  | `"json"` or `"df"` (DataFrame-like) |
| `debug`         | boolean | Enables verbose logging             |

***

### 📤 Output Example

Each record includes:

- `url` – Source URL
- `markdown` – Full converted content
- `chunks` – Markdown split into sections by heading

```json
{
  "url": "https://apify.com",
  "markdown": "# Welcome to Apify\n...",
  "chunks": [
    "# Welcome to Apify",
    "## What is Apify?",
    "## Get Started"
  ]
}
```

***

### ▶️ Usage

You can run this actor:

#### 🟣 Apify CLI

```bash
apify call antonio_espresso/html-to-markdown-converter --input '{ "urls": ["https://apify.com"] }'
```

#### 🐍 Python

```python
import requests

ACTOR_ID = "antonio_espresso/html-to-markdown-converter"
TOKEN = "APIFY_API_TOKEN"  # Replace with your token

response = requests.post(
    f"https://api.apify.com/v2/actor-tasks/{ACTOR_ID}/runs",
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={"urls": ["https://apify.com"], "output_format": "json"}
)

print(response.json())
```

***

### 👨‍💻 Author

Made with ❤️ by [SEO Antonio Blago](https://antonioblago.de)

#### 🔗 My Other Apify Actors:

- 🔍 [Competitor-Based Keyword Recommendations](https://apify.com/antonio_espresso/keyword-competitor-recommendation)
- 🧠 [LLMs.txt Generator](https://apify.com/antonio_espresso/llms-txt-generator)
- 💡 [AI Prompt Keyword Matcher](https://apify.com/antonio_espresso/ai-prompt-keyword-matcher)
- 📰 [Markdown to Social Media Post](https://apify.com/antonio_espresso/markdowntosocialmediapost)
- 🌐 [HTTP Status Codes and URL Checker](https://apify.com/antonio_espresso/website-status-code-crawler)

***

### ⚙️ Tech Stack

- Python 3.10+
- Apify SDK for Python
- Advertools for Markdown generation

***

### 🧪 Local Dev

```bash
pip install -r requirements.txt
python src/markdown_convert.py
```

Push to Apify:

```bash
apify push
```

***

### 🧼 License

MIT

# Actor input Schema

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

List of URLs to crawl and convert HTML to Markdown.

## `output_format` (type: `string`):

Choose the format of the output data.

## `debug` (type: `boolean`):

Enable verbose logging and extra info in the dataset.

## Actor input object example

```json
{
  "urls": [
    "https://apify.com"
  ],
  "output_format": "json",
  "debug": false
}
```

# 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"
    ],
    "output_format": "json",
    "debug": false
};

// Run the Actor and wait for it to finish
const run = await client.actor("antonio_espresso/html-to-markdown-converter").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"],
    "output_format": "json",
    "debug": False,
}

# Run the Actor and wait for it to finish
run = client.actor("antonio_espresso/html-to-markdown-converter").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"
  ],
  "output_format": "json",
  "debug": false
}' |
apify call antonio_espresso/html-to-markdown-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,antonio_espresso/html-to-markdown-converter"
        }
    }
}
```

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/DAhYTRBGufIWdreOf/builds/N1EwEoEvjdl0KvMRb/openapi.json
