#1 Webseite von PV Wechselrichter auslesen?
Verfasst: Fr 15. Mär 2013, 18:34
von KlausM
hallo,
ist es möglich einen Wert von einer Webseite auszulesen und den Spannungswert in eine Base Value zu speichern? Hier ein Ausschnitt von meiner PV Wechselrichter Webseite...
Das Script müsste nach "Voltage Eingang 1" im quellcode suchen und den Wert der darauf folgenden span class value ins Base als Wert übernehmen..
Danke für Eure Hilfe
#2 RE: Webseite von PV Wechselrichter auslesen?
Verfasst: Mo 20. Mai 2013, 11:34
von KlausM
Da Siebo das gleiche nur für LinHK sucht bin ich auch mal wieder an mein Vorhaben erinnert worden
Also ich würde gerne eine HTML Seite mit einem kleinen lua Script parsen.
Habe mal gegoogelt und was gefunden das sich vieleicht verwenden lässt. Allerdings hat das Script die Aufgabe eine HTML Seite zu bereinigen und als Textdatei zu speichern. Könnte man diesen Code umbiegen für mein Vorhaben?
Code: Alles auswählen
--[[
HTML Parser in Lua
Inspired by this C# code:
http://www.codeproject.com/useritems/HTML_to_Plain_Text.asp
It does exactly the same as described there.
Only converts offline files.
Distributed under a modified BSD license, see at the end of the file]]
-- What is the desired newline?
nl = "\n"
filename = "E:/luaorg.htm"
function HTML_ToText (file)
-- Declare variables, load the file. Make tags lowercase.
local text
local f=io.open (file)
if f then
if f:seek("end") ]-)>)",function (str) return str:lower() end)
--[[
First we kill the developer formatting (tabs, CR, LF)
and produce a long string with no newlines and tabs.
We also kill repeated spaces as browsers ignore them anyway.
]]
local devkill=
{
["("..string.char(10)..")"] = " ",
["("..string.char(13)..")"] = " ",
["("..string.char(15)..")"] = "",
["(%s%s+)"]=" ",
}
for pat, res in pairs (devkill) do
text = string.gsub (text, pat, res)
end
-- Then we remove the header. We do this by stripping it first.
text = string.gsub (text, "(]*>)", "")
text = string.gsub (text, "()", "")
text = string.gsub (text, "(,*)", "")
-- Kill all scripts. First we nuke their attribs.
text = string.gsub (text, "(]*>)", "")
text = string.gsub (text, "()", "")
text = string.gsub (text, "(,*)", "")
-- Ok, same for styles.
text = string.gsub (text, "(]*>)", "")
text = string.gsub (text, "()", "")
text = string.gsub (text, "(.*)", "")
-- Replace and with tabulators.
text = string.gsub (text, "(]*>)","\t")
text = string.gsub (text, "(]*>)","\t")
-- Replace with linebreaks.
text = string.gsub (text, "()",nl)
-- Replace with an asterisk surrounded by spaces.
-- Replace with a newline.
text = string.gsub (text, "()"," * ")
text = string.gsub (text, "()",nl)
-- , , , will be replaced to a double newline.
text = string.gsub (text, "(]*>)", nl..nl)
text = string.gsub (text, "(]*>)", nl..nl)
text = string.gsub (text, "(]*>)", nl..nl)
text = string.gsub (text, "(]*>)", nl..nl)
-- Some petting with the tags. :-P
local addresses,c = {},0
text=string.gsub(text,"]*>(.-)]->", -- gets URL from a tag, and the enclosed name
function (url,name)
c = c + 1
name = string.gsub (name, "]-)>","") -- strip name from tags (e. g. images as links)
-- We only consider the URL valid if the name contains alphanumeric characters.
if name:find("%w") then print(url, name, c) table.insert (addresses, {url, name}) return name.."["..#addresses.."]" else return "" end
end)
-- Nuke all other tags now.
text = string.gsub (text, "(%b)","")
-- Replace entities to their correspondant stuff where applicable.
-- C# is owned badly here by using a table. :-P
-- A metatable secures entities, so you can add them natively as keys.
-- Enclosing brackets also get added automatically (capture!)
local entities = {}
setmetatable (entities,
{
__newindex = function (tbl, key, value)
key = string.gsub (key, "(%#)" , "%%#")
key = string.gsub (key, "(%&)" , "%%&")
key = string.gsub (key, "(%;)" , "%%;")
key = string.gsub (key, "(.+)" , "("..key..")")
rawset (tbl, key, value)
end
})
entities =
{
[" "] = " ",
["•"] = " * ",
["‹"] = "",
["™"] = "(tm)",
["⁄"] = "/",
[""] = ">",
["©"] = "(c)",
["®"] = "(r)",
-- Then kill all others.
-- You can customize this table if you would like to,
-- I just got bored of copypasting. :-)
-- http://hotwired.lycos.com/webmonkey/reference/special_characters/
["%&.+%;"] = "",
}
for entity, repl in pairs (entities) do
text = string.gsub (text, entity, repl)
end
-- text = text..nl..nl..("-"):rep(27)..nl..nl
--
-- for k,v in ipairs (addresses) do
-- text = text.."["..k.."] "..v[1]..nl
-- end
if #addresses > 0 then
text=text..nl:rep(2)..("-"):rep(2)..nl
for key, tbl in ipairs(addresses) do
text = text..nl.."["..key.."]"..tbl[1]
end
end
return text
end
local f=io.open(filename..".txt", "w")
f:write(HTML_ToText (filename))
f:close()
--[[
Copyright (c) 2007, bastya_elvtars
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
to endorse or promote products derived from this code without specific
prior written permission.
THIS CODE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]
#3 RE: Webseite von PV Wechselrichter auslesen?
Verfasst: Do 23. Mai 2013, 18:28
von Thomas
Hallo Klaus,
hm, glaube fast, das wird eng im BASE.
Was aber geht, von einem anderen Rechner die Werte rausholen, und an das Base in VAR's senden.
Gruss Thomas
#4 RE: Webseite von PV Wechselrichter auslesen?
Verfasst: Do 23. Mai 2013, 20:25
von KlausM
Hallo Thomas,
Jo...kann sein das daß too much wird
Wenn ich das mit der Anmeldung am Webif mal raus habe kann ich ja mal ein bischen probieren.
Gruß
Klaus