Web scraping text and looking result up in table

I am using http-request to get the text from this website:
https://ewn.co.za/assets/loadshedding/api/status

All I want to do is get the data after a certain set of words, for example: "City Customers: Stage " and then whatever number is located there.

From there I want to lookup the number in this table:

and get time slots which shows when my area will be load shed (Welcome to Africa).

Any assistance would be greatly appreciated.

You could use regular expressions using a capture group in a Function node
to filter out the number from the text.

msg.payload = msg.payload.match(/CITY CUSTOMERS: STAGE (\d)+ /)
msg.payload = Number(msg.payload[1]) // get 1st regex group and convert to number

return msg;

Test Flow:

[{"id":"87b731dda38031a3","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":1520,"wires":[["81b689f8a88f21dc"]]},{"id":"81b689f8a88f21dc","type":"http request","z":"54efb553244c241f","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://ewn.co.za/assets/loadshedding/api/status","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":450,"y":1520,"wires":[["ca748687180a5ae1","23dd45c26e3acc66"]]},{"id":"ca748687180a5ae1","type":"function","z":"54efb553244c241f","name":"function 1","func":"\nmsg.payload = msg.payload.match(/CITY CUSTOMERS: STAGE (\\d)+ /)\nmsg.payload = Number(msg.payload[1]) // get 1st regex group and convert to number\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1520,"wires":[["8bfb25d4f46c7fef"]]},{"id":"23dd45c26e3acc66","type":"debug","z":"54efb553244c241f","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":1460,"wires":[]},{"id":"8bfb25d4f46c7fef","type":"debug","z":"54efb553244c241f","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":1520,"wires":[]}]

regarding matching that number from a pdf file .. for that i have no idea
maybe copy paste and patiently edit the data to a JS array that you can later use as a lookup table.

Thank you. The regex expression worked. First time using it as I'm very new to Node Red.

Next up is to figure out the JS array and looking up the stage and time slots from it.

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