This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Get temperature data from web page
#10
(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
Reply


Messages In This Thread
RE: Get temperature data from web page - by fleeceable - 23.08.2023, 15:07

Forum Jump: