23.11.2022, 15:49
Hi Robikozo,
Below code will fetch any data from a webpage.
All you have to do is look into the source html of the webpage and copy paste the html part you are interested in.
Take into account that hard returns have to be defined as /n
Replace the part you want to fetch with (.-)
Below example fetched the latest Endex 303 prices from the Belgian Engie website
Hope this helps!
Below code will fetch any data from a webpage.
All you have to do is look into the source html of the webpage and copy paste the html part you are interested in.
Take into account that hard returns have to be defined as /n
Replace the part you want to fetch with (.-)
Below example fetched the latest Endex 303 prices from the Belgian Engie website
Code:
-- Scraping a value from a webpage
-- https://www.domoticz.com/forum/viewtopic.php?t=25321
-- https://forum.logicmachine.net/showthread.php?tid=4386
https = require 'ssl.https'
url = 'https://www.engie.be/nl/energie/elektriciteit-gas/prijzen-voorwaarden/indexatieparameters/indexatieparameters-elektriciteit'
status = ssl.https.request(url)
-- find matching string and fetch the data you want with (.-)
response=status:match('<span class="table_mobile_header"><p><strong>Endex 303</strong></p>\n</span>\n<span class="table_mobile_data"><div >\n<p>(.-)</p>')
response = string.gsub(response, ',', '.') -- replace comma seperated floating number to point
response = tonumber(response) -- replace string number to number
log(response)
Hope this helps!