Skip to main content
Version: 1.28 (Current)

Clean HTML

Audience: Low-code Engineers

Skill 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.

note

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​

Action NameDescription
Fetch ContentDownloads a page and extracts its content, title and text.
Sanitize HtmlRemoves unsafe markup, such as scripts and event handlers.
Server RequestSends an HTTP request and returns the raw response.
Markdown to HtmlConverts Markdown to HTML.
Summarize ContentSummarizes text with OpenAI.
ChatSends a message to an OpenAI chat model.

Input Parameter Reference​

ParameterDescriptionSupports TokensDefaultRequired
Raw HTMLThe HTML to clean, usually a token such as [PageHtml]. If it's empty, the action fails with Supply the raw html.Yesempty stringYes
Store Clean HTMLThe 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.Noempty stringYes

Output Parameters Reference​

ParameterDescription
Store Clean HTMLHolds 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:

  1. 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.
  2. Clutter is removed. Every nav, header, footer, script, style, link and img tag is removed, with its content.
  3. Attributes are removed. Only href, title and alt are kept. class, id, style, src and event handlers such as onclick are removed.
  4. 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 its src. HTML comments are removed too.
  5. Wrappers are unwrapped. A div or span with 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 &amp;. Links aren't changed, so relative links stay relative.

Before and after​

Input:

<body><nav>Menu</nav><main><h1 class="x">News &amp; 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 &amp; views</h1><p>Read the <a href="/story">full story</a>.</p>

Considerations​

  • The order of the content can change. When a div or span with 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 href values aren't checked, so javascript: and data: links stay. Tags like iframe or form stay 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 /story stays 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 Error or Ignore Errors, so the error stops execution unless an enclosing Execute Actions catches it.

Examples​

tip

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