NEWS
Werte von Webseite speichern
-
Hallo Zusammen,
in JavaScript bin ich leider nicht so bewandert. Wenn ich Vorlagen habe kann ich ganz gut auf meine Bedürfnisse anpassen, aber irgendwie finde ich für mein aktuelles Problem nicht passendes:
Was ich vorhabe:
Der RMV bietet recht schöne "Abfahrtstafeln" an, die man sich selber konfigureren kann. Man bekommt dann einen Link, den man in Vis sehr schön einbinden kann:
https://www.rmv.de/auskunft/bin/jp/stbo … 40&start=1
Das Ergebniss sieht dann so aus:
Für Vis ideal, aber jetzt würde ich gerne die geplanten und aktuelles Abfahrtszeiten auch Objekt abspeichern. Dazu würde ich gerne ein Script schreiben, dass die Webseite aufruft und die 6 Zeiten in 6 verschiedene Objekte schreibt. Ich könnte auch den Parser Adapter nehmen, aber da müsste ich ja 6 Instanzen erstellen, da ich dort immer nur einen Wert pro Adapter speichern kann.
Kann mir da jemand mal eine kleine Vorlage schreiben?
Danke und viele Grüße,
Balu
-
Hallo Balu,
ich hole mir die Abfahrtszeiten so wie hier beschrieben:
Du musst nicht für jede Abfrage eine neue Instanz vom Parser erstellen. Einfach "Neue Regel" anklicken.
Danke für den Hinweis mit den Abfahrtstafeln, muss ich gleich mal testen.
-
Hi Gerhard,
Danke für Deine Antwort.
Wenn ich die URL im Parser Adapter eintrage bekomme ich nur den http Header. Wenn ich mir den Quelltext im Browser anschaue stehen die Werte da auch gar nicht mehr drin. So wird es also nicht funktionieren.
Der RMV bietet auch eine API an. Aber da wird es ganz schwarz bei mir…
Wenn es interessiert:
https://opendata.rmv.de/site/start.html
Dort gibt es auch den Link zur Konfiguration der "Individuellen Abfahrtstafel"
Grüße,
Balu
-
ich verwende diese URL:
http://reiseauskunft.bahn.de/bin/query. … rt&start=1
funktioniert problemlos
-
Hallo,
du bist nicht allein: ich bastel auch gerade an den RMV Abfahrtstafeln für meine VIS.
Ich nutze dafür die vom RMV angebotene XML-Schnittstelle.
Zurückgeliefert wird etwas wie (Beispiel für eine Bahn aus dem XML):
... <journey trainid="1866608008"><journeyattributelist><journeyattribute to="14" from="8"><attribute type="NAME" priority="-1"><attributevariant type="NORMAL"><text>U6</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="8"><attribute type="CATEGORY" priority="-1"><attributecode>4</attributecode> <attributevariant type="LONG"><text>U-Bahn</text></attributevariant> <attributevariant type="SHORT"><text>BU5</text></attributevariant> <attributevariant type="NORMAL"><text>U-Bahn</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="8"><attribute type="INTERNALCATEGORY" priority="-1"><attributevariant type="NORMAL"><text>BU5</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="8"><attribute type="OPERATOR" priority="-1"><attributevariant type="LONG"><text>Stadtwerke Verkehrsgesellschaft Frankfurt</text></attributevariant> <attributevariant type="SHORT"><text>VGF</text></attributevariant> <attributevariant type="NORMAL"><text>VGF</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="8"><attribute type="NUMBER" priority="-1"><attributevariant type="NORMAL"><text>U6</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="8"><attribute type="DIRECTION" priority="-1"><attributevariant type="NORMAL"><text>Frankfurt (Main) Ostbahnhof</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="0"><attribute type="INFO" priority="-1"><attributecode>FD</attributecode> <attributevariant type="NORMAL"><text>60066</text></attributevariant></attribute></journeyattribute> <journeyattribute to="14" from="8"><attribute type="EXTERNALID" priority="-1"><attributevariant type="NORMAL"><text>13846</text></attributevariant></attribute></journeyattribute></journeyattributelist> <mainstop><basicstop index="8"><location type="WGS84" y="50119950" x="8653924"><station><externalid pooluic="80">3001201</externalid> <hafasname><text>Frankfurt (Main) Bockenheimer Warte</text></hafasname></station></location> <dep><time>09:14</time></dep></basicstop></mainstop></journey> ...
Derzeit versuche ich das zurück-gelieferte XML mit dem systeminfo-Adapter in eine JSON-Tabelle zu wandeln und als Objekte zu speichern.
Kämpfe aber noch mit der Umwandlung des XML in entsprechende Objekte.
Grüße,
Maeb
-
Hallo Maeb,
ja, das ist ziemlich genau das Problem, wo ich auch bin.
Du bist aber schon ein wenig weiter als ich. Um Dieses XML zu bekommen musstest Du Dich anmelden, oder?
Wie sieht denn der Request dazu aus?
Ich bin im Moment dabei mit node red mal die Rückgaben von der Bahnseite die Robert nutzt in einzelne Objekte zu packen. Bin aber auch noch nicht weit, da ich node red auch noch nie benutzt habe.
Der Parser Adapter läuft bei mir leider nicht richtig. Bei jeder zweiten Abfrage liefert er ein leeres Ergebniss…
Danke und Grüße,
Balu
-
Ging bei mir ohne Anmeldung, wenn ich mich recht erinnere:
Unter https://www.rmv.de/auskunft/bin/jp/stbo … zeigetafel die entsprechenden Parameter konfigurieren (als Format xml auswählen) und dann den entsprechenden Link (Vorschau) verwenden.
Der Link sieht dann z.B. so aus:
https://www.rmv.de/auskunft/bin/jp/stbo … utput=xml&
Jetzt muss ich mich irgendwann nochmal hinsetzen und per RegExp die relevanten Objekte ermitteln, um dann in etwa folgendes Array von Objekten zu generieren (trainId | NAME | DIRECTION | Time | Delay). da tue ich mich aber verdammt schwer.
Falls du das besser hinbekommst, lass mich gerne teilhaben
Grüße, maeb
-
Prima, Danke.
Ich hoffe ich komme am Wochenende dazu mal weiter zu probieren. Aber auch ich tue mir damit sehr schwer.
Programmieren und Scripten geht in meine Gehirnwindungen nicht rein
Wenn ich was hab sage ich Bescheid.
Gruß,
Balu
-
Bin jetzt eigentlich am Ziel.
Ich bin jetzt wieder auf die XML Variante direkt vom RMV gewechselt, aber erstmal bei node red geblieben. Das Ergebniss:
[ { "id": "c2e8a228.ce75a", "type": "inject", "z": "6214dd4e.ed2b74", "name": "manueller Start", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 160, "y": 200, "wires": [ [ "9748880f.17aa98" ] ] }, { "id": "9b30d083.a4886", "type": "xml", "z": "6214dd4e.ed2b74", "name": "XML -> Objects", "property": "payload", "attr": "", "chr": "", "x": 600, "y": 200, "wires": [ [ "5a537dae.e837a4", "11667978.787987", "956de415.5de428", "c997de37.9d9bd", "fa59f000.66649", "7f6fef3e.45c23", "2a81bd77.3b4fa2" ] ] }, { "id": "5a537dae.e837a4", "type": "function", "z": "6214dd4e.ed2b74", "name": "Abfahrt 0", "func": "msg.payload = msg.payload.ResC.SBRes[0].JourneyList[0].Journey[0].MainStop[0].BasicStop[0].Dep[0].Time\nreturn msg;", "outputs": 1, "noerr": 0, "x": 860, "y": 60, "wires": [ [ "2d94d037.f99f1" ] ] }, { "id": "11667978.787987", "type": "function", "z": "6214dd4e.ed2b74", "name": "Abfahrt 1", "func": "msg.payload = msg.payload.ResC.SBRes[0].JourneyList[0].Journey[1].MainStop[0].BasicStop[0].Dep[0].Time\nreturn msg;", "outputs": 1, "noerr": 0, "x": 860, "y": 120, "wires": [ [ "899471ca.19f5b" ] ] }, { "id": "956de415.5de428", "type": "function", "z": "6214dd4e.ed2b74", "name": "Abfahrt 2", "func": "msg.payload = msg.payload.ResC.SBRes[0].JourneyList[0].Journey[2].MainStop[0].BasicStop[0].Dep[0].Time\nreturn msg;", "outputs": 1, "noerr": 0, "x": 860, "y": 180, "wires": [ [ "b46de57a.c2c608" ] ] }, { "id": "9748880f.17aa98", "type": "http request", "z": "6214dd4e.ed2b74", "name": "Abfrage RMV", "method": "GET", "ret": "txt", "url": "https://www.rmv.de/auskunft/bin/jp/stboard.exe/dn?L=vs_anzeigetafel&cfgfile=FrankfurtM_3001501_2055304888&outputMode=xml&start=yes&output=xml&", "tls": "", "x": 360, "y": 200, "wires": [ [ "9b30d083.a4886" ] ] }, { "id": "2d94d037.f99f1", "type": "ioBroker out", "z": "6214dd4e.ed2b74", "name": "Richtung Konstablerwache 0", "topic": "javascript.0.RMV.Departure.Guenthersburgpark.to_Konstablerwache.Departure0", "ack": "true", "autoCreate": "false", "x": 1200, "y": 60, "wires": [] }, { "id": "899471ca.19f5b", "type": "ioBroker out", "z": "6214dd4e.ed2b74", "name": "Richtung Konstablerwache 1", "topic": "javascript.0.RMV.Departure.Guenthersburgpark.to_Konstablerwache.Departure1", "ack": "true", "autoCreate": "false", "x": 1200, "y": 120, "wires": [] }, { "id": "b46de57a.c2c608", "type": "ioBroker out", "z": "6214dd4e.ed2b74", "name": "Richtung Konstablerwache 2", "topic": "javascript.0.RMV.Departure.Guenthersburgpark.to_Konstablerwache.Departure2", "ack": "true", "autoCreate": "false", "x": 1200, "y": 180, "wires": [] }, { "id": "c997de37.9d9bd", "type": "function", "z": "6214dd4e.ed2b74", "name": "Verspätung 0", "func": "msg.payload = msg.payload.ResC.SBRes[0].JourneyList[0].Journey[0].MainStop[0].BasicStop[0].Dep[0].Delay\nreturn msg;", "outputs": 1, "noerr": 0, "x": 870, "y": 240, "wires": [ [ "639eab37.461804" ] ] }, { "id": "fa59f000.66649", "type": "function", "z": "6214dd4e.ed2b74", "name": "Verspätung 1", "func": "msg.payload = msg.payload.ResC.SBRes[0].JourneyList[0].Journey[1].MainStop[0].BasicStop[0].Dep[0].Delay\nreturn msg;", "outputs": 1, "noerr": 0, "x": 870, "y": 300, "wires": [ [ "929155a7.7af118" ] ] }, { "id": "7f6fef3e.45c23", "type": "function", "z": "6214dd4e.ed2b74", "name": "Verspätung 2", "func": "msg.payload = msg.payload.ResC.SBRes[0].JourneyList[0].Journey[2].MainStop[0].BasicStop[0].Dep[0].Delay\nreturn msg;", "outputs": 1, "noerr": 0, "x": 870, "y": 360, "wires": [ [ "e5362d2f.4c73e", "c391efa6.a63cd" ] ] }, { "id": "639eab37.461804", "type": "ioBroker out", "z": "6214dd4e.ed2b74", "name": "Richtung Konstablerwache Verspätung 0", "topic": "javascript.0.RMV.Departure.Guenthersburgpark.to_Konstablerwache.Delay0", "ack": "true", "autoCreate": "false", "x": 1240, "y": 240, "wires": [] }, { "id": "929155a7.7af118", "type": "ioBroker out", "z": "6214dd4e.ed2b74", "name": "Richtung Konstablerwache Verspätung 1", "topic": "javascript.0.RMV.Departure.Guenthersburgpark.to_Konstablerwache.Delay1", "ack": "true", "autoCreate": "false", "x": 1240, "y": 300, "wires": [] }, { "id": "e5362d2f.4c73e", "type": "ioBroker out", "z": "6214dd4e.ed2b74", "name": "Richtung Konstablerwache Verspätung 2", "topic": "javascript.0.RMV.Departure.Guenthersburgpark.to_Konstablerwache.Delay2", "ack": "true", "autoCreate": "false", "x": 1240, "y": 360, "wires": [] }, { "id": "2a81bd77.3b4fa2", "type": "debug", "z": "6214dd4e.ed2b74", "name": "alles als Objekte / Arrays", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "x": 910, "y": 520, "wires": [] }, { "id": "c391efa6.a63cd", "type": "debug", "z": "6214dd4e.ed2b74", "name": "nur Wert Verspätung 2", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "x": 1180, "y": 520, "wires": [] } ]
Funktioniert einwandfrei. Mal schauen ob ich noch Lust habe es als JavaScript zu versuchen…
Grüße,
Balu