This is a custom n8n node that uses Cheerio to parse HTML content.
- Parse HTML using multiple CSS selectors
- Convert selected output to array or string
- Clone this repository
- Install dependencies:
npm install
- Build the node:
npm run build
- Link to your n8n installation:
npm link
- In your n8n installation directory, run:
npm link n8n-nodes-cheerio-parser
- Add the "Cheerio Parser" node to your workflow
- Input the HTML content you want to parse
- Specify a CSS selector (e.g., "div.content", "p.title", "#main")
- Choose your desired output type (single or array)
- Connect the node to your workflow
Input HTML:
<div class="content">
<h1>Title</h1>
<p>Some text</p>
</div>
With selector: .content h1
and output type: text
, the node will return:
{
"result": "Title"
}
Input HTML:
<div class="article">
<h1 class="title">Welcome to my blog</h1>
<div class="content">
<p>First paragraph of content</p>
<p>Second paragraph of content</p>
</div>
</div>
Node Configuration:
{
"selectors": [
{
"name": "title",
"selector": "h1.title",
"singleItem": true
},
{
"name": "paragraphs",
"selector": "div.content p",
"singleItem": false
}
]
}
Output:
{
"results": {
"title": "<h1 class=\"title\">Welcome to my blog</h1>",
"paragraphs": [
"<p>First paragraph of content</p>",
"<p>Second paragraph of content</p>"
]
},
"total": {
"selectors": 2,
"elements": 3
}
}
To run tests:
npm test