gelöst: HTTPMOD Hilfestellung

Begonnen von gent, 30 April 2018, 20:18:48

Vorheriges Thema - Nächstes Thema

gent

Hallo zusammen,

möchte mir jemand helfen, ein Reading per httpmod von der Seite https://www.westmetall.com/de/markdaten.php z.B. die "untere Kupfer DEL-Notiz" zu erstellen?

Was ich herausfinden konnte ist, dass der Xpath dahin wie folgt aussieht:


//*[@id="content"]/div/table[4]/tbody/tr[3]/td[2]/a


oder der Teil im HTML


<a class="block" href="?action=show_diagram&amp;field=DEL_low">568,80</a>


Ich brauche also ein Reading DEL_LOW mit dem Wert 568,80

Meine Test Definition sieht so aus:


defmod testWM HTTPMOD http://www.westmetall.com/de/markdaten.php 300
attr testWM userattr reading01Name reading01XPath
attr testWM reading01Name DEL_LOW
attr testWM reading01XPath //*[@id="content"]/div/table[4]/tbody/tr[3]/td[2]/a


Ich bekomme aber das definierte Reading "DEL_LOW" nicht.

Ich vermute, dass das an den "//" im XPath liegt, die so nicht erkannt werden.

Hat Irgendjemand eine Idee, warum ich kein Reading erhalte?

Viele Grüße vom Gent
fhem auf rPi3 mit USB boot und M2, cul866 (hm), homebridge, FlowerSens, Shelly, Harmony, WemosD1, Sonoff/Tasmota, grafana, mqtt/mosquitto

gent

Ich versuch's halt nochmal mit ein paar mehr Informationen

Mit Verbose=5 bekomme ich folgenden Output:


2018.05.02 19:19:03 5: testWM: InitParsers: XPath parsing done.
2018.05.02 19:19:03 5: testWM: ExtractSid called, context reading, num
2018.05.02 19:19:03 4: testWM: CheckAuth decided no authentication required
2018.05.02 19:19:03 5: testWM: Read starts parsing response to update with defined readings: 01
2018.05.02 19:19:03 5: testWM: ExtractReading DEL_LOW with XPath //*[@id="content"]/div/table[4]/tbody/tr[3]/td[2]/a
2018.05.02 19:19:03 5: testWM: ExtractReading DEL_LOW did not match
2018.05.02 19:19:03 3: testWM: Read response to update didn't match any Reading
2018.05.02 19:19:03 5: testWM: HandleSendQueue called, qlen = 0
2018.05.02 19:24:03 3: testWM: Read response to update didn't match any Reading


Interessant ist für mich die Zeile "ExtractReading DEL_LOW did not match".

Vielleicht hat jemand noch einen Tipp für mich.

Viele Grüße vom Gent
fhem auf rPi3 mit USB boot und M2, cul866 (hm), homebridge, FlowerSens, Shelly, Harmony, WemosD1, Sonoff/Tasmota, grafana, mqtt/mosquitto

amenomade

Das ist kein XML sondern HTML
Mach es mit Regex statt XPath
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

gent

Hi amenomade,

es sollte doch eigentlich beides gehen, aber wenn ich mich täusche, dann geht natürlich auf regex.

Vielen Dank.
fhem auf rPi3 mit USB boot und M2, cul866 (hm), homebridge, FlowerSens, Shelly, Harmony, WemosD1, Sonoff/Tasmota, grafana, mqtt/mosquitto

supernova1963

Nicht sehr professionell, aber es funktioniert:
defmod Kupfer HTTPMOD https://www.westmetall.com/de/markdaten.php 60
attr Kupfer userattr reading01Name reading01Regex
attr Kupfer reading01Name Wert
attr Kupfer reading01Regex Deutsche Metallnotierungen<\/th>[\w\W]*?action=show_diagram&field=DEL_low">[\w\W]*?action=show_diagram&field=DEL_low">(?P<Wert>.*?)<\/a>
attr Kupfer stateFormat Wert

gent

Hallo supernova1963

vielen Dank. Das hat mir sehr geholfen.

Viele Grüße vom Gent
fhem auf rPi3 mit USB boot und M2, cul866 (hm), homebridge, FlowerSens, Shelly, Harmony, WemosD1, Sonoff/Tasmota, grafana, mqtt/mosquitto

amenomade

Nochmal zum Thema XPath: ja, das sollte auch it XPath statt XPath-Strict funktionieren. Tut es aber nicht. Bis /div/table[4]/tbody/tr[3] geht alles gut. Ein Schritt weiter (td) ist das Ergebnis leer. Das kann man auch hier testen: xpather.com. Das hängt wahrscheinlich an tbody in der html Seite.

Deswegen die Empfehlung auf regex zu wechseln.
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus