Parsing Webpage Using HttpClient

Hi

I’m trying to read electricity prices from this webpage using HttpClient:
http://www.electricityinfo.co.nz/comitFta/ftaPage.main

Looking at the source code, it’s not clear to me where these prices are coming from. I was hoping to find an API in the HTML source that the data may be coming from but I suppose this is being done server side and the HTML is displaying the data from a database?

Anyhow, would it be possible to write a function using HttpClient that parses the response for the different divs (e.g. price wkm2201) and returns the price as a string/int?

Sorry I’m a bit new to this!

If you are looking to extract the data from the webpage, it is fairly straightforward.
What you do is ‘Get’ the page, and then search it for a unique phrase that is always the same.
In this case there is “price wkm2201”.
That will give you the starting point of that phrase. Then you add the number of characters to count from the start of that phrase to where the actual data the you want starts, and you end with another search (in this case , to where the end of the desired data.

I use this in one of my searches:

http.get(request, response, headers);
String Result1  = (response.body.substring (response.body.indexOf ("<elevation>")+11,response.body.indexOf ("</elevation>")));

Be sure to increase your buffer so it will fit the entire page at least up to the data that you want.

You can convert a string to an int with atoi() or a float with atof()

2 Likes

Thanks very much @Awake, I haven’t had a chance to try this yet but I’ll post back when I do.