# HTML parse node issue

**URL:** <https://discourse.nodered.org/t/html-parse-node-issue/53987>\
**Category:** General\
**Created:** [19 November 2021 10:18 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987 "2021-11-19T10:18:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![esalles](https://avatars.discourse-cdn.com/v4/letter/e/ac8455/32.png) [@esalles](https://discourse.nodered.org/u/esalles)\
**Post date:** [19 November 2021 10:18 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/1 "2021-11-19T10:18:28Z")

</div>

Hi Guys,

I've discovered a behavior difference of HTML parsing node according to Node-Red version (and maybe node.js version ??).

The following flow is just a "foo" string in msg.palyoad that shall be parsed in msg.payload output a array.

This works well on Node-red v1.2.6 (node.js v12.18.0), but not on v2.1.3 (Node.js v17.1.0).

I've already seen that before, but did put attention on this since a implemented bypass. THis means this issue not only related to that newest version...

I'm sure I'm not the only one facing this issue, but I cannot find any info about it on the web.

Can somebody help to fix this?

`[{"id":"f15e247e303f869c","type":"inject","z":"8499110d.f4114","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":330,"y":1400,"wires":[["9fbc3115654d8932"]]},{"id":"9fbc3115654d8932","type":"function","z":"8499110d.f4114","name":"","func":"msg.payload = \"<td>foo</td>\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":1420,"wires":[["3daf3e4160f3b523"]]},{"id":"3daf3e4160f3b523","type":"html","z":"8499110d.f4114","name":"Get row data","property":"payload","outproperty":"payload","tag":"td","ret":"html","as":"single","x":770,"y":1420,"wires":[["38a638931bab31ce"]]},{"id":"38a638931bab31ce","type":"debug","z":"8499110d.f4114","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":950,"y":1420,"wires":[]}]`

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [19 November 2021 13:57 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/2 "2021-11-19T13:57:27Z")

</div>

Hello,

This was reported a while back from @bakman2 in this [thread](https://discourse.nodered.org/t/html-node-not-extracting-content/50795/8)

The issue is with the html parser Cheerio.js library the Html node uses.

its due to your string not being a full html document but a fragment.  
(github page where Bakman opened the [issue](https://github.com/cheeriojs/cheerio/issues/2096))

* * *

@knolleary  
I played around with the Html node code where cheerio is used  
`var $ = cheerio.load(value, null, false);`  
seems to fix the issue but i didnt do much testing (just a cookbook [example](https://cookbook.nodered.org/http/simple-get-request) and Esalles flow)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 November 2021 14:02 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/3 "2021-11-19T14:02:24Z")

</div>

Yes, that fixes this issue, but at the expense of breaking the majority use case where you do pass in a valid document.

The change to the underlying module of the HTML node was highlighted in the 2.0 release notes as a potential area of breaking change - although at the time we weren't 100% sure of what edge cases the change would manifest.

We have an item on the backlog to add an option to the HTML node to put it into fragment mode.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [19 November 2021 14:52 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/4 "2021-11-19T14:52:23Z")

</div>

> [@knolleary](#):
>
> but at the expense of breaking the majority use case where you do pass in a valid document

yea thats always a big problem with code changes 🧐

in the case of the cookbook example where an http request is done on the the NodeRed home page and select the `.node-red-latest-version`, even if we pass the whole document as a fragment it still picks up the correct element .. i didnt notice any side effects .. but you are right, an option would be the safest.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 November 2021 15:08 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/5 "2021-11-19T15:08:07Z")

</div>

I believe the “fragment” part they were referring to was more related to a td being part of a table/thead fragment (in the html spec)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [19 November 2021 15:32 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/6 "2021-11-19T15:32:00Z")

</div>

> [@bakman2](#):
>
> in the html spec

```auto
<tr>
    <td>100</td>
    <td>200</td>
    <td>300</td>
</tr>

```

so cheerio because the above is not according to html specs it doesnt consider it as valid (table) and doesnt parse it ?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 November 2021 16:38 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/7 "2021-11-19T16:38:10Z")

</div>

Indeed, if you put table tags around it, it works.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 January 2022 16:38 UTC](https://discourse.nodered.org/t/html-parse-node-issue/53987/8 "2022-01-18T16:38:15Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
