Splitting an array

I’m stumped by this and I think it should be easy!

Lets say I have a html file:

<html>
   <head>
   </head>
   <body>
      <p>Para 1</p>
      <p>Para 2</p>
      <p>Para ...</p>
      <p>Updated: 21 July 2020</p>
   </body>
<html>

I want the “Updated…” paragraph

I’m getting the html using a HTML.Request and then selecting just the “P” content using a HTML.Text node.

However that then produces a json with all the text in a single array:

- [
-    {
-         "Text" : [
                         "Para 1",
                         "Para 2",
                         "Para ...",
                         "Updated 21 July 2020"
                       ]
       }
]

I was expecting Each Text: as a seperate entry rather than an array and then to run an IF node on it.

Can I get it like that? Or is there a way to do it? I Don’t seem able to get any of the function examples to work

Welcome to the community @CALUM_POLWART!

You can do the following to split it into different items:

{
  "nodes": [
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "text",
              "cssSelector": "p",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        700,
        600
      ]
    },
    {
      "parameters": {
        "functionCode": "return items[0].json.text.map(text => { return { json: { text } } });\nreturn items;"
      },
      "name": "Split-Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        850,
        600
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.data = `<html>\n   <head>\n   </head>\n   <body>\n      <p>Para 1</p>\n      <p>Para 2</p>\n      <p>Para ...</p>\n      <p>Updated: 21 July 2020</p>\n   </body>\n<html>`;\nreturn items;"
      },
      "name": "Mock Input-Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        550,
        600
      ]
    }
  ],
  "connections": {
    "HTML Extract": {
      "main": [
        [
          {
            "node": "Split-Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock Input-Data": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thank you.
Pretty sure that there is witchcraft… but it works!

Sorry I am really not allowed to talk about this!

1 Like