Clean HTML
Audience:
Low-code EngineersSkill Prerequisites:
Tokens,HTML
Extracts the main content from a full HTML page and stores it in a token. Navigation, headers, footers, scripts, styles and images are removed, and so are most attributes. What's left is simple HTML with just the content.
It's the same cleanup that Fetch Content does after it downloads a page. Use Clean HTML when you already have the HTML, for example from a Server Request.
Clean HTML isn't a security filter. To remove unsafe markup, use Sanitize Html.
This action is part of the Web Crawler add-on (PlantAnApp.WebCrawler). The add-on is installed separately and needs the WEBCRWL feature in your license. If it isn't licensed, the action fails with a not-licensed error. If you don't see the Web Crawler actions, the add-on isn't installed.
Typical Use Cases
- Get the article part of a page returned by a Server Request, without the menus and footer
- Shrink a page before you send it to Chat or Summarize Content, so it uses fewer AI tokens
- Remove styles, classes and inline scripts from HTML before you store it
Don't use it to
- Make HTML safe to display. Use Sanitize Html instead.
javascript:links pass through Clean HTML. - Download a page. Use Fetch Content instead.
- Get plain text. Use Fetch Content with
Store Plain Text. - Convert Markdown. Use Markdown to Html instead.
- Clean HTML where the order of the content matters exactly. See Considerations.
Related Actions
| Action Name | Description |
|---|---|
| Fetch Content | Downloads a page and extracts its content, title and text. |
| Sanitize Html | Removes unsafe markup, such as scripts and event handlers. |
| Server Request | Sends an HTTP request and returns the raw response. |
| Markdown to Html | Converts Markdown to HTML. |
| Summarize Content | Summarizes text with OpenAI. |
| Chat | Sends a message to an OpenAI chat model. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Raw HTML | The HTML to clean, usually a token such as [PageHtml]. If it's empty, the action fails with Supply the raw html. | Yes | empty string | Yes |
| Store Clean HTML | The token name that gets the cleaned HTML, for example CleanedHtml. If it's empty, the action fails with There is no output token defined to save the clean HTML. | No | empty string | Yes |
Output Parameters Reference
| Parameter | Description |
|---|---|
| Store Clean HTML | Holds the cleaned HTML. It's the inner content of the part that was kept, without the <html>, <body>, <article> or <main> tag around it. |
How the HTML is cleaned
The HTML is parsed with Html Agility Pack and cleaned in this order:
- The main part is picked. It's the
<article>if the page has exactly one, otherwise the<main>if the page has exactly one, otherwise the<body>. If there's no<body>, the whole HTML is used. - Clutter is removed. Every
nav,header,footer,script,style,linkandimgtag is removed, with its content. - Attributes are removed. Only
href,titleandaltare kept.class,id,style,srcand event handlers such asonclickare removed. - Empty tags are removed. A tag with no attributes, no children and no text goes, for example an empty
<p>, a<br>, or an<iframe>that lost itssrc. HTML comments are removed too. - Wrappers are unwrapped. A
divorspanwith only one child is removed, and its child is moved to the end of the parent. See Considerations.
Everything else stays as it is: other tags such as table, form, noscript or svg, the text, and HTML entities such as &. Links aren't changed, so relative links stay relative.
Before and after
Input:
<body><nav>Menu</nav><main><h1 class="x">News & views</h1><p>Read the <a href="/story" onclick="track()">full story</a>.</p><img src="photo.jpg" alt="Photo"><script>track()</script></main><footer>Contact</footer></body>
Result:
<h1>News & views</h1><p>Read the <a href="/story">full story</a>.</p>
Considerations
- The order of the content can change. When a
divorspanwith one child is unwrapped, the child is moved to the end of its parent. For example,<p>Hello <span>world</span>, friend</p>becomes<p>Hello , friendworld</p>, and<div><p>First</p></div><p>Second</p>becomes<p>Second</p><p>First</p>. Check the result on your real pages. - It isn't sanitization. Event handlers are removed, but
hrefvalues aren't checked, sojavascript:anddata:links stay. Tags likeiframeorformstay when they still have content. Run Sanitize Html on the result before you show it on a page. - Images are always removed. There's no option to keep them.
- Relative links aren't fixed. A link like
/storystays relative. There's no base URL setting. - More than one article. If the page has several
<article>tags, none is picked on its own. The<main>or the<body>is used instead. - Both parameters are required. An empty input or an empty output token name fails the action. There's no
On ErrororIgnore Errors, so the error stops execution unless an enclosing Execute Actions catches it.
Examples
To understand how to use the below examples, please see Running Examples.
1. Extract the article from a page
This action keeps only the article part of the HTML and stores it in CleanedHtml.
{
"Title": "Clean HTML",
"ActionType": "WebCrawler.CleanHtml",
"Description": "Extract the article content",
"Parameters": {
"RawHtml": "<html><head><title>Sample Page</title></head><body><nav>Navigation</nav><article><h1>Title</h1><p>Content</p></article><footer>Footer</footer></body></html>",
"StoreCleanHtml": "CleanedHtml"
}
}
After it runs, [CleanedHtml] contains:
<h1>Title</h1><p>Content</p>
2. Clean a server response
This action cleans the HTML in [PageHtml], for example the response of a Server Request. It runs only when [PageHtml] isn't empty, so the action doesn't fail.
{
"Title": "Clean HTML",
"ActionType": "WebCrawler.CleanHtml",
"Description": "Clean the downloaded page",
"Condition": "[PageHtml] != \"\"",
"Parameters": {
"RawHtml": "[PageHtml]",
"StoreCleanHtml": "PageContent"
}
}
Revised 09/28/2026