Skip to content

zzzarius/n8n-nodes-cheerio-parser

Repository files navigation

n8n-nodes-cheerio-parser

This is a custom n8n node that uses Cheerio to parse HTML content.

Features

  • Parse HTML using multiple CSS selectors
  • Convert selected output to array or string

Installation

  1. Clone this repository
  2. Install dependencies:
npm install
  1. Build the node:
npm run build
  1. Link to your n8n installation:
npm link
  1. In your n8n installation directory, run:
npm link n8n-nodes-cheerio-parser

Usage

  1. Add the "Cheerio Parser" node to your workflow
  2. Input the HTML content you want to parse
  3. Specify a CSS selector (e.g., "div.content", "p.title", "#main")
  4. Choose your desired output type (single or array)
  5. Connect the node to your workflow

Example

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"
}

Complete Example

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
  }
}

Development

To run tests:

npm test

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published