Best way to scrape Website data using HTTP Binding OH3


Looking to upgrade my 2.5 installation to 3. The issue im having is getting my weather station info into OH 3.

Whats the best way to scrape the UV data from the webpage below?

Ive had a go with using REGEX, as im using that in my 2.5 instance, but cant get it to work :unamused:

2.5 Item:

Number WeatherUV2 "Outdoor LUX [%.1f lx]" <sun> 							  {http="<[weatherstationCache:30000:REGEX(.*?uv.*?value=\"(.*?)\".*)]"}


Clearly your http-1config can’t be used, as you cannot install http-1 binding in OH3.
If only we knew what you did try in OH3, we might be able to help.

I relise my V1 binding doesnt work. I installed the V3 binding, created a THING and an item…

But my main question is how would you implament it, not neccessarily using REGEX. Could i use another method?

Nothing wrong with REGEX. More complex analysis with if-and-but conditions can be carried out in a rule.
Link a plain String to your Thing as well initially, see that the HTML that you expect arrives, before you look at transformation problems.

there are different ways. I am not sure which one the best way could be.
E.g. I am more focused on doing stuff on command line that in the UI. So I would create a shell script and do something like

curl http://URL-here -O - | grep '"uv"' /tmp/abc  | sed -e 's/.*value="//' | sed -e 's/".*//'

and call that script from executeComandLine or the exec binding.
This is not tested so some fine tuning might be required.

It‘s also possible to use the JS-Transformation for more complex analysis.

To OP: if you have the regex at hand, I would go with the REGEX transformation. First remove the transformation and link the Channel to a string item. Do you get the raw data? If not, something is wrong with the thing or channel Config. If so, add the regex and see what happens.

1 Like

If you are lazy, like me, I can recommend this site for generating regexp
I have used it quite alot, really good imo.

Regards S