Seitenquelltext zerhacken

Hallo,

kann mir jemand beim zerhacken behilflich sein?

Da es irgenwie mit dem Problem „CMI“ nicht weitergeht erstelle ich mir eine Seite zum Auslesen. Aber ich brächte Starthilfe wie ich die Werte vom Quelltext rausbekomme.

Ich weiß dass ich einen WWW-Reader und eine Registervariable mit Auswert-Skript brauche.
Hat jemand ein Beispielskript wie ich folgendes zerhacken kann?

<div id="pos0" >
 11,7 °C</div>
<div id="pos1" >
 59,5 °C</div>
<div id="pos2" >
 33,2 °C</div>
<div id="pos3" >
 46,3 °C</div>
<div id="pos4" >
 63,0 °C</div>
<div id="pos5" >
 47,9 °C</div>
<div id="pos6" >
 36,2 °C</div>
<div id="pos7" >
  5,3 °C</div>
<div id="pos8" >
 25,3 °C</div>
<div id="pos9" >
 41,1 °C</div>
<div id="pos10" >
 38,7 °C</div>
<div id="pos11" >
AUS</div>
<div id="pos12" >
  2,8 °C</div>
<div id="pos13" >
  4,6 °C</div>
<div id="pos14" >
  2,5 °C</div>
<div id="pos15" >
  5,5 °C</div>
<div id="pos16" >
AUS</div>
<div id="pos17" >
AUS</div>

Hallo,

Leider komm ich hier nicht weiter. Kann mir jemand helfen?
Ich müsste hier auf „echte“ Variablen umwandeln.

Mein Skript:

<?

if ($_IPS['SENDER'] == "RegisterVariable")
 {
    // bereits im Puffer der Instanz vorhandene Daten in $data kopieren
    $data  = RegVar_GetBuffer($_IPS['INSTANCE']);
    // neu empfangene Daten an $data anhängen
    $data .= $_IPS['VALUE'];
	$date = trim($data);
	$data = str_replace(array("
", "\r", "
"), '', $data);  
 	$data = str_replace(array("div id=",">","/div","°C","<"),'',$data);
	$data = str_replace(',','.',$data);
	//echo $data;
 	$arr = explode('"',$data);
	print_r ($arr);
	//echo (count($arr));
 	echo ($arr[2]);
	
	
	SetValue(20283 /*[Zuhaus\UVR1611\UVR1611 (CMI)\Sensor (01) Solarkolektor]*/, $arr[2]);
	SetValue(54754 /*[Zuhaus\UVR1611\UVR1611 (CMI)\Sensor (02) Puffer oben]*/, $arr[4]);
	
	SetValue(12570 /*[Zuhaus\UVR1611\UVR1611 (CMI)\A1 Solarpumpe]*/, boolval($data[34]));
	SetValue(30681 /*[Zuhaus\UVR1611\UVR1611 (CMI)\A2 Ladepumpe Heizkessel]*/, $data[36]);


	
	
Ergebnis:

21.02.2019 09:35:32 | Register Variable | Array
(
    [0] => S
    [1] => pos0
    [2] =>   23.0 
    [3] => pos1
    [4] =>   46.8 
    [5] => pos2
    [6] =>   24.1 
    [7] => pos3
    [8] =>   28.8 
    [9] => pos4
    [10] =>   28.6 
    [11] => pos5
    [12] =>   20.6 
    [13] => pos6
    [14] =>   19.4 
    [15] => pos7
    [16] =>    5.3 
    [17] => pos8
    [18] =>   18.9 
    [19] => pos9
    [20] =>   28.3 
    [21] => pos10
    [22] =>   28.3 
    [23] => pos11
    [24] =>  AUS
    [25] => pos12
    [26] =>    3.7 
    [27] => pos13
    [28] =>    4.3 
    [29] => pos14
    [30] =>    3.1 
    [31] => pos15
    [32] =>    5.6 
    [33] => pos16
    [34] =>  AUS
    [35] => pos17
    [36] =>  AUS
)
  23.0 <br />
<b>Warning</b>:  Variable is marked as read-only and cannot be changed in <b>/var/lib/symcon/scripts/42058.ips.php</b> on line <b>20</b><br />
<br />
<b>Warning</b>:  Variable is marked as read-only and cannot be changed in <b>/var/lib/symcon/scripts/42058.ips.php</b> on line <b>21</b><br />
<br />
<b>Warning</b>:  Cannot auto-convert value for parameter VariableValue in <b>/var/lib/symcon/scripts/42058.ips.php</b> on line <b>23</b><br />
<br />
<b>Warning</b>:  Variable is marked as read-only and cannot be changed in <b>/var/lib/symcon/scripts/42058.ips.php</b> on line <b>24</b><br />
}    
?>

Ergebnis:


Ich würde in dem Fall die Seite komplett abholen und dann die Elemente per DomDocument auslesen.

[ul]
[li]DOM XPath (Auslesen/Parsen von Webseiten)[/li][li]DOMDocument::getElementById[/li][li]DOMDocument und DOMXPath[/li][/ul]

Ich frage keine HTML-Seite ab:

192.168.2.34/schematic_files/12.CGI?user&pwd


<div id="pos0" >
 46,7 °C</div>
<div id="pos1" >
 46,4 °C</div>
<div id="pos2" >
 27,2 °C</div>
<div id="pos3" >
 32,0 °C</div>
<div id="pos4" >
 28,2 °C</div>
<div id="pos5" >
 20,5 °C</div>
<div id="pos6" >
 19,4 °C</div>
<div id="pos7" >
  7,6 °C</div>
<div id="pos8" >
 29,1 °C</div>
<div id="pos9" >
 28,0 °C</div>
<div id="pos10" >
 26,0 °C</div>
<div id="pos11" >
AUS</div>
<div id="pos12" >
  3,6 °C</div>
<div id="pos13" >
  4,3 °C</div>
<div id="pos14" >
  3,1 °C</div>
<div id="pos15" >
  5,9 °C</div>
<div id="pos16" >
EIN</div>
<div id="pos17" >
AUS</div>
<div id="pos18" >
EIN</div>
<div id="pos19" >
AUS</div>
<div id="pos20" >
AUS</div>
<div id="pos21" >
AUS</div>
<div id="pos22" >
AUS</div>
<div id="pos23" >
AUS</div>
<div id="pos24" >
AUS</div>
<div id="pos25" >
AUS</div>
<div id="pos26" >
AUS</div>
<div id="pos27" >
AUS</div>


Gibt es noch andere Möglichkeiten?

Am Einfachsten wäre es doch hier einfach eingebaute Funktionen von Symcon zu verwenden die das für dich tun:

Zuerst die URL lesen mit dem WWW Reader:
https://www.symcon.de/service/dokumentation/modulreferenz/io/wwwreader/

Dann die Daten mit dem Textparser teilen und in Variablen schieben:
https://www.symcon.de/service/dokumentation/modulreferenz/textparser/

Schon ausprobiert?

Gruß, Lutz

Klar das würde auch gehen. Nur dann habe ich die Ergebnisse in „String“ und muss sie auch wieder recht aufwendig weiterverarbeiten.

Solange die Ergebnisse konvertierbar sind, schreibt der Parser sie korrekt in die entsprechende Variable.
Ich z.B. schreibe so Messwerte aus einer Webseite direkt in Float.

Gruß, Lutz

Zum Beispiel so:

<?
$int = GetValueString(55204); // Holt den wert aus String
$float = (float)$int; //ändert diesen ab
$float = floatval($int);
SetValueFloat(13747, $float);//Und setzt ihn in den Float
?>

Nur weil Dir anscheinend der HTML Header fehlt ist das dennoch HTML. Du must dann halt wieder HTML Tags hinzufügen, dann kannst Du das auch simpel auslesen.


 $data = '<div id="pos0" >
 11,7 °C</div>
<div id="pos1" >
 59,5 °C</div>
<div id="pos2" >
 33,2 °C</div>
<div id="pos3" >
 46,3 °C</div>
<div id="pos4" >
 63,0 °C</div>
<div id="pos5" >
 47,9 °C</div>
<div id="pos6" >
 36,2 °C</div>
<div id="pos7" >
  5,3 °C</div>
<div id="pos8" >
 25,3 °C</div>
<div id="pos9" >
 41,1 °C</div>
<div id="pos10" >
 38,7 °C</div>
<div id="pos11" >
AUS</div>
<div id="pos12" >
  2,8 °C</div>
<div id="pos13" >
  4,6 °C</div>
<div id="pos14" >
  2,5 °C</div>
<div id="pos15" >
  5,5 °C</div>
<div id="pos16" >
AUS</div>
<div id="pos17" >
AUS</div>';

$payload = '<!DOCTYPE html>
<html lang="de">
<head>
  <title>Data for IP-Symcon</title>
</head>
<body>'. $data. '</body>
</html>';

$doc = new DomDocument;
$doc->loadHTML($payload);

// Element mit id pos0 auslesen
$DomElement_pos0 = $doc->getElementById( 'pos0' ); 
$pos0 = $DomElement_pos0->nodeValue;
$pos0 = utf8_decode($pos0);
var_dump($pos0);

SetValue(12345, $pos0); // 12345 Objekt ID der Variable

Vielen Dank für eure Hilfe. Ich habe es so versucht.

https://www.symcon.de/forum/newreply.php?do=newreply&p=378433