HTTP Request Node and special characters

Hey all!

A rather fresh (~1 year on/off) node-red user here! I'm having trouble parsing a webpage which includes Scandinavian letters like ä/ö.

Here's an example flow:

[{"id":"a02852a0.3a07","type":"tab","label":"Encoding Tests","disabled":false,"info":""},{"id":"ba38d1f4.0b2","type":"debug","z":"a02852a0.3a07","name":"Parsed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":900,"y":240,"wires":[]},{"id":"3d216b95.a0462c","type":"http request","z":"a02852a0.3a07","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"{{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":240,"wires":[["44e88e2.6e44ef"]]},{"id":"44e88e2.6e44ef","type":"html","z":"a02852a0.3a07","name":"get element","property":"payload","outproperty":"payload","tag":".tori_title","ret":"html","as":"single","x":730,"y":240,"wires":[["ba38d1f4.0b2"]]},{"id":"2bac3368.a6e15c","type":"inject","z":"a02852a0.3a07","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":240,"wires":[["d9494d1.7e55d3"]]},{"id":"d9494d1.7e55d3","type":"function","z":"a02852a0.3a07","name":"URL","func":"msg.payload = \"https://muusikoiden.net/tori/ilmoitus/1649213\"\n\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":240,"wires":[["3d216b95.a0462c"]]},{"id":"54040bdd.f1a7a4","type":"debug","z":"a02852a0.3a07","name":"Example","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":900,"y":80,"wires":[]},{"id":"d3a70029.6e347","type":"inject","z":"a02852a0.3a07","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":80,"wires":[["ac69c829.ec2388"]]},{"id":"ac69c829.ec2388","type":"function","z":"a02852a0.3a07","name":"Generate \"wanted\" response","func":"msg.payload = [\"<b>Myydään:</b> Doepfer Dark Energy II\"]\n\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":80,"wires":[["54040bdd.f1a7a4"]]},{"id":"47282f0f.c3322","type":"comment","z":"a02852a0.3a07","name":"Should be like this!","info":"","x":530,"y":40,"wires":[]},{"id":"a980b970.cebc2","type":"function","z":"a02852a0.3a07","name":"Encoding","func":"msg.payload = msg.payload.toString('iso-8859-15')\n\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":340,"wires":[[]]},{"id":"2f26623b.167b7e","type":"comment","z":"a02852a0.3a07","name":"Tried out encoding, didn't work","info":"","x":720,"y":300,"wires":[]},{"id":"19bf0ef.76b9c71","type":"comment","z":"a02852a0.3a07","name":"But gives out this..","info":"","x":530,"y":200,"wires":[]}]

In short, I'm trying to read some elements from a webpage using a combination of the HTTP Request, as well as the HTML parser nodes. At the moment, I'm able to get the right elements with the HTML parser, but some of characters don't display properly at the debug-window. I added an alternative branch to the flow to show how they should look like, and also to confirm that, at least in my node-red instance, the debugger should be able to display the letters correctly.

I'm always a little confused with this encoding and decoding stuff, so I figured that instead of banging my head against the wall by myself, maybe some of you kind folks at the forum could guide me!

Thanks a lot for your time!

Hey all!

I'm bumping this topic since I'm still struggling with the issue.

My flow is currently otherwise finished, I have the backend doing what it's supposed to do, and I'm getting notified by the things I'd like to. The only problem is the aesthetics of the resulting HTML page that carries the notifications. All the scandinavian literals translate as question marks, which doesn't really make the outsome so pretty.

If anyone can point me to the right direction with this, any help is appreciated!

[{"id":"ba38d1f4.0b2","type":"debug","z":"a02852a0.3a07","name":"Parsed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1780,"y":240,"wires":[]},{"id":"3d216b95.a0462c","type":"http request","z":"a02852a0.3a07","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"{{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":1770,"y":160,"wires":[["a980b970.cebc2"]]},{"id":"44e88e2.6e44ef","type":"html","z":"a02852a0.3a07","name":"get element","property":"payload","outproperty":"payload","tag":".tori_title","ret":"text","as":"multi","x":1610,"y":240,"wires":[["ba38d1f4.0b2"]]},{"id":"2bac3368.a6e15c","type":"inject","z":"a02852a0.3a07","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1440,"y":160,"wires":[["d9494d1.7e55d3"]]},{"id":"d9494d1.7e55d3","type":"function","z":"a02852a0.3a07","name":"URL","func":"msg.payload = \"https://muusikoiden.net/tori/ilmoitus/1649213\"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1590,"y":160,"wires":[["3d216b95.a0462c"]]},{"id":"a980b970.cebc2","type":"function","z":"a02852a0.3a07","name":"Encoding","func":"\nmsg.payload = msg.payload.toString(\"latin1\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1420,"y":240,"wires":[["44e88e2.6e44ef"]]}]
1 Like

Aah, thanks a lot @Steve-Mcl! That did it! Seems I was very close already.

Judging from your flow example, it seems it's also important not to return the HTML-contents of the elements with the HTML parser node (but rather the text contents) if you want to have properly rendered text in the debugger node. I think I might have tried the latin1-encoding within the encoding-function at some point, but since I was returning the HTML-contents, the debugger-node didn't render the results properly. Like said, this encoding/decoding business is still somewhat confusing for me..

Anyways, thanks a lot your time and help!! I added the encoding to the bigger flow, and everything displays as it should in the HTML output! Woohoo!

You're welcome.

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