23.08.2023, 15:07
(23.08.2023, 13:49)Ohmarn Wrote: Hi,
Since you kindly helped me last time, they've change the website and now i have to update the script..
Is anyone willing to help me, again?
Source URL
Value marked with blue.
Best regards //Simon
Used ChatGTP for this:
Code:
url = 'https://www.havochvatten.se/badplatser-och-badvatten/vattenprov-badtemperatur/vattentemperatur-och-kvalitet-pa-badvatten-pa-sydkusten.html'
data = require('socket.http').request(url)
-- Function to extract the temperature for a specific location
local function extractTemperatureForLocation(html, locationName)
local locationStartIdx, locationEndIdx = html:find(locationName)
if not locationStartIdx then
return nil
end
local temperatureStartIdx, temperatureEndIdx, temperature = html:find("(%d+%.%d+)°C", locationEndIdx)
if not temperatureStartIdx then
return nil
end
return temperature
end
-- Location name to search for
local locationName = "Yngsjö havsbad"
-- Extract temperature for the specific location
local temperature = extractTemperatureForLocation(data, locationName)
if temperature then
-- Print the extracted temperature
--log(locationName .. " temperature: " .. temperature .. "°C")
grp.checkwrite('10/5/101', temperature)
else
log(locationName .. " temperature not found.")
end