HTML extract: How to do if/else condition within the node?

I’ve the following html

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css" style="display:none;">
        P {margin-top:0;margin-bottom:0;}
    </style>
</head>

<body dir="ltr">
    <div>
        <div dir="ltr">
            <div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
                <table style="font-family:arial,sans-serif; border-collapse:collapse; width:798px; font-size:medium; orphans:2; widows:2">
                    <tbody>
                        <tr>
                            <th style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">System</th>
                            <th style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Priority</th>
                            <th style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Country</th>
                        </tr>
                        <tr style="background-color:rgb(150,221,221)">
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Linux</td>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">High</td>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Germany</td>
                        </tr>
                        <tr>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Windows</td>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Medium</td>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Mexico</td>
                        </tr>
                        <tr style="background-color:rgb(221,221,221)">
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">AIX</td>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Low</td>
                            <td style="border:1px solid rgb(221,221,221); text-align:left; padding:8px">Austria</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>

The aim is to extract and send

  • Rows with => background-color:rgb(150,221,221) , then send those ROWS to node1 (for action2)
  • When cells of “system == Windows” , then send those ROWS to node2 (for action2)

I was able to extract the rows table>tbody>tr as below

But How to send the data into different nodes based on condition? Is there any place I can write conditions within the HTML extract? I’ve written IF node outside the HTML extract, but it either receives “attributes” or Extracted fields only. But I’m looking for the entire ROW data to maintain the relation. Hence was looking for an if/else condition within the HTML extract node

Hi @getk, the HTML Extract node only has one output, so it would always send all results to it without applying additional conditions. So you’d always need to use additional nodes for filtering.

Seeing you would like to keep the entire row data, the first thing I’d do here would be to convert each row into individual n8n items. This can be done using the Item Lists node:

You could then use two IF nodes to check each condition separately and perform the actions you have in mind:

Example Workflow

The entire row would be available after both IF nodes in the above example:

Hope this helps!

1 Like

thanks a lot @MutedJam . This answer is very comprehensive and well explained. I will try this out and again much appreciated

1 Like