How to remove the first empty key and value from the HTML Extract return

I tried to make a similar workflow through the introduction of HTML Extract (It helped me a lot!)

However, due to the design of the site, every time I run it, it returns a null value

This leads to error messages in the later work (node)

Is there any way to remove it?

Hey @Han, welcome to the community :tada:

So your data extraction is working in principle, but it just returns some empty items you’d like to filter out?

You could use an IF node to account for that and check if either your url field or your title field are empty like so:

Hope this helps! Let me know if you have any questions on this :slight_smile:

I tried to filter them with if, but I got the following result

I’m thinking that this result may be due to the fact that the previous node’s data was not located correctly , because the first data is blank, so it will display --EMPTY–, is there a solution for this situation?

Oh, sorry for that. Could you share your workflow (or alternatively the JSON output from your HTML Extract node) so I can have a go with your actual data?

here there are :slight_smile:

{
  "nodes": [
    {
      "parameters": {
        "dataPropertyName": "item",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": "a",
              "returnValue": "html"
            },
            {
              "key": "url",
              "cssSelector": "a",
              "returnValue": "attribute",
              "attribute": "href"
            }
          ]
        },
        "options": {
          "trimValues": false
        }
      },
      "name": "HTML Extract01",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        490,
        280
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "item",
              "cssSelector": "tr",
              "returnValue": "html",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        360,
        280
      ]
    },
    {
      "parameters": {
        "url": "https://home.gamer.com.tw/subscribe_creation.php?owner=jason990505&type=subscribe",
        "responseFormat": "string",
        "options": {
          "useQueryString": false
        },
        "queryParametersUi": {
          "parameter": [
            {}
          ]
        }
      },
      "name": "HTTP Get",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        240,
        280
      ]
    }
  ],
  "connections": {
    "HTML Extract": {
      "main": [
        [
          {
            "node": "HTML Extract01",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Get": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
`
1 Like

Thanks so much! I’ve tried combining your workflow with my IF node:

…and this seems to remove the empty item just fine (meaning only the correct ones are left over on the “Items with title and url” node):

Did you try to execute the suggested workflow in its entirety? If this still fails for you, can you confirm which version of n8n you are currently running?

sorry, my version is 0.127.0, did not find an update is my fault

I will try again after the update :no_mouth:

Thanks to your help, I did it!
Finally I used

{{{$node["HTML Extract01"].json["title"]}}

to solve the problem.
The only difference is that I didn’t specify a title.
To do this in the absence of input data is a bit difficult, please forgive me for being a novice. :sweat_smile:

Anyway, thanks for your help, and n8n Team :heart:


On a side note, it doesn’t seem to show when I use </> to insert the code?


Like this, I can’t see any code

1 Like

Glad to hear this works!

As for the code not showing up, I have the same problem with Firefox and Ublock activated. It seems to work fine on Chrome though or in Firefox’ private mode though:

Might be one for @mutdmour to check (perhaps we can fall back to the default JSON view of the forum if the workflow plugin is blocked?).

Should be working now. You might have to do a hard browser refresh (command + shift + R) or clear the cache. If you are still seeing issues, please share device and browser type/version information.

2 Likes