HTML Extract data between h2 tags

I am sorry if this has been asked, I did look through the questions and I have spent quite a fair bit of time googling this.

I am trying to use html extract to pull all the data after a specific h2 tag is used and until the next tag begins. I do not seem to see a way to get this working within n8n, so any help would be appreciated.

Thanks in advance.

Welcome to the community @DrSeussFreak

We use cheerio under the hook. So, any selector supported by cheerio can be used. Check the example below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -60,
        270
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "under",
              "cssSelector": "h2",
              "returnValue": "html"
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        440,
        270
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      data: `<h2>data within the tag</h2>`\n    }\n  }\n]\n\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        170,
        270
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thank you, I’m not familiar with cheerio, but I’ll be doing some reading. Thanks Again!

Hey @DrSeussFreak,

Welcome to the community :sparkling_heart:

Did you find a solution? Let us know if you need more help :slight_smile: