Http - Parse value of an element attribute? (DOM getAttribute())

Hey there!

I'm looking for a clean way to get the value of an attribute in an HTML element, similarly as the getAttribute() function [*] would allow. Is there something in node-red that would provide similar functionality? At the moment getting the value of an attribute requires me writing some specific javascript string-matching, which doesn't feel so clean.

*Element.getAttribute() - Web APIs | MDN

Put another way, how would you extract the URL from an HTML element similar as below?

<img src="https://something.interesting.com" alt=\"210103_1\">

Thank you for your help!

Assuming you mean in node-red (and not client side)...

[{"id":"dab3993734b39446","type":"inject","z":"eb3bd3ff.33367","name":"<img src=\"https://something.inte...","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<img src=\"https://something.interesting.com\" alt=\\\"210103_1\\\">","payloadType":"str","x":1960,"y":100,"wires":[["0c5f6a136547526b"]]},{"id":"0c5f6a136547526b","type":"html","z":"eb3bd3ff.33367","name":"","property":"payload","outproperty":"payload","tag":"img","ret":"attr","as":"single","x":1990,"y":160,"wires":[["e1196d058c5e8456"]]},{"id":"e1196d058c5e8456","type":"debug","z":"eb3bd3ff.33367","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2030,"y":220,"wires":[]}]
1 Like

Thanks a lot @Steve-Mcl, that did it! I think I even tried the "object of attributes"-option in the HTTP-parser at some point, but it was only giving me empty arrays.. I must have had the CSS selector wrong, damn it I should tried harder. Anyways, thanks again!

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