I'm trying to get the data out of a bus schedule. It should update in real time. The page I want to do this with is https://fahrplan.oebb.at/bin/stboard.exe/dn?L=...vs_liveticker&evaId=493034&boardType=dep&productsFilter=1011111111011&dirInput=&tickerID=dep&start=yes&eqstops=false&showJourneys=12&additionalTime=0. I tried downloading the page's html source every 30 seconds and accessing the table from there but the downloaded file only includes the javascript which generates the table, not the table itself. Is there a way to either run the script locally and save the data to a file or to get the server to run the script? Thank you in advance!
CodePudding user response:
You need a bit more gymnastics before getting to some usable info, given the binary response. First, you can get the api endpoint scrapeed via XHR by inspecting the Dev Tools - Network tab in Chrome browser. The following code will return some meaningful data:
import requests
import pandas as pd
import json
url = 'https://fahrplan.oebb.at/bin/stboard.exe/dn?L=...vs_liveticker&evaId=493034&boardType=dep&time=10:05&productsFilter=1011111111011&additionalTime=0&disableEquivs=yes&maxJourneys=50&outputMode=tickerDataOnly&start=yes&selectDate=today'
r = requests.get(url)
json_obj = json.loads(r.text.split('journeysObj = ')[1])
df = pd.json_normalize(json_obj['journey'])
print(df)
This will return:
id | ti | da | pr | st | lastStop | ati | tr | trChg | rt | rta | rt.status | rt.dlm | rt.dlt | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 479996818 | 10:13 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 10:39 | False | 0 | False | nan | nan | nan | |
1 | 479996819 | 10:16 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 10:54 | False | 0 | False | nan | nan | nan | |
2 | 479996819 | 10:28 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 10:54 | False | 0 | False | nan | nan | nan | |
3 | 4799968110 | 10:31 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 11:09 | False | 0 | False | nan | nan | nan | |
4 | 4799968110 | 10:43 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 11:09 | False | 0 | False | nan | nan | nan | |
5 | 4799968111 | 10:46 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 11:24 | False | 0 | False | nan | nan | nan | |
6 | 4799968111 | 10:58 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 11:24 | False | 0 | False | nan | nan | nan | |
7 | 437788811 | 11:01 | 16.08.2022 | Bus 646 | Wels Hbf via Krenglbach | Wels Hbf (Busterminal) | 11:09 | False | nan | False | nan | 4 | 11:05 | |
8 | 4799968112 | 11:01 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 11:39 | False | 0 | False | nan | nan | nan | |
9 | 4799968112 | 11:13 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 11:39 | False | 0 | False | nan | nan | nan | |
10 | 4799968113 | 11:16 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 11:54 | False | 0 | False | nan | nan | nan | |
11 | 4799968113 | 11:28 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 11:54 | False | 0 | False | nan | nan | nan | |
12 | 4799968114 | 11:31 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 12:09 | False | 0 | False | nan | nan | nan | |
13 | 437838812 | 11:40 | 16.08.2022 | Bus 646 | Aistersheim | Aistersheim Kriegerdenkmal | 12:19 | False | 0 | False | nan | nan | nan | |
14 | 4799968114 | 11:43 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 12:09 | False | 0 | False | nan | nan | nan | |
15 | 4799968115 | 11:46 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 12:24 | False | 0 | False | nan | nan | nan | |
16 | 4799968115 | 11:58 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 12:24 | False | 0 | False | nan | nan | nan | |
17 | 4799968116 | 12:01 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 12:39 | False | 0 | False | nan | nan | nan | |
18 | 4799968116 | 12:13 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 12:39 | False | 0 | False | nan | nan | nan | |
19 | 4799968117 | 12:16 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 12:54 | False | 0 | False | nan | nan | nan | |
20 | 4799968117 | 12:28 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 12:54 | False | 0 | False | nan | nan | nan | |
21 | 4799968118 | 12:31 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 13:09 | False | 0 | False | nan | nan | nan | |
22 | 4799968118 | 12:43 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 13:09 | False | 0 | False | nan | nan | nan | |
23 | 4799968119 | 12:46 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 13:24 | False | 0 | False | nan | nan | nan | |
24 | 4799968119 | 12:58 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 13:24 | False | 0 | False | nan | nan | nan | |
25 | 437811810 | 13:00 | 16.08.2022 | Bus 646 | Aistersheim | Aistersheim Kriegerdenkmal | 13:39 | False | 0 | False | nan | nan | nan | |
26 | 437788812 | 13:01 | 16.08.2022 | Bus 646 | Wels Hbf via Krenglbach | Wels Hbf (Busterminal) | 13:09 | False | 0 | False | nan | nan | nan | |
27 | 4799968120 | 13:01 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 13:39 | False | 0 | False | nan | nan | nan | |
28 | 4799968120 | 13:13 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 13:39 | False | 0 | False | nan | nan | nan | |
29 | 4799968121 | 13:16 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 13:54 | False | 0 | False | nan | nan | nan | |
30 | 4799968121 | 13:28 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 13:54 | False | 0 | False | nan | nan | nan | |
31 | 4799968122 | 13:31 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 14:09 | False | 0 | False | nan | nan | nan | |
32 | 437866810 | 13:40 | 16.08.2022 | Bus 646 | Pichl b.Wels | Pichl b.Wels Ortsmitte | 14:03 | False | 0 | False | nan | nan | nan | |
33 | 4799968122 | 13:43 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 14:09 | False | 0 | False | nan | nan | nan | |
34 | 4799968123 | 13:46 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 14:24 | False | 0 | False | nan | nan | nan | |
35 | 4799968123 | 13:58 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 14:24 | False | 0 | False | nan | nan | nan | |
36 | 4799968124 | 14:01 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 14:39 | False | 0 | False | nan | nan | nan | |
37 | 4799968124 | 14:13 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 14:39 | False | 0 | False | nan | nan | nan | |
38 | 4799968125 | 14:16 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 14:54 | False | 0 | False | nan | nan | nan | |
39 | 437853810 | 14:20 | 16.08.2022 | Bus 646 | Haag am Hausruck | Haag am Hausruck Bahnhofstraße | 15:00 | False | 0 | False | nan | nan | nan | |
40 | 4799968125 | 14:28 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 14:54 | False | 0 | False | nan | nan | nan | |
41 | 437802811 | 14:31 | 16.08.2022 | Bus 646 | Wels Hbf via Krenglbach | Wels Hbf (Busterminal) | 14:39 | False | 0 | False | nan | nan | nan | |
42 | 4799968126 | 14:31 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 15:09 | False | 0 | False | nan | nan | nan | |
43 | 4799968126 | 14:43 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 15:09 | False | 0 | False | nan | nan | nan | |
44 | 4799968127 | 14:46 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 15:24 | False | 0 | False | nan | nan | nan | |
45 | 4799968127 | 14:58 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 15:24 | False | 0 | False | nan | nan | nan | |
46 | 437988810 | 15:00 | 16.08.2022 | Bus 646 | Meggenhofen | Meggenhofen Pendlerparkplatz | 15:34 | False | 0 | False | nan | nan | nan | |
47 | 4799968128 | 15:01 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 15:39 | False | 0 | False | nan | nan | nan | |
48 | 4799968128 | 15:13 | 16.08.2022 | Bus 2 | Wels Ghegastraße | Wels Machstraße | 15:39 | False | 0 | False | nan | nan | nan | |
49 | 4799968129 | 15:16 | 16.08.2022 | Bus 2 | Flemingstraße | Wels Machstraße | 15:54 | False | 0 | False | nan | nan | nan |
CodePudding user response:
You can use request module to get the data by hitting the API directly which fetches the data.
You can change the param time=14:32
according to your requirement.
import requests
r = requests.get('https://fahrplan.oebb.at/bin/stboard.exe/dn?L=...vs_liveticker&evaId=493034&boardType=dep&time=14:32&productsFilter=1011111111011&additionalTime=0&disableEquivs=yes&maxJourneys=50&outputMode=tickerDataOnly&start=yes&selectDate=today')
print(r.content)
which gives us the expected output
b'journeysObj = {\n"headTexts":["Zeit","Fahrt","Nach","Steig","Abfahrten","Aktuell","Ankunft"],\n"stationName":"Wels Heimstättenring",\n"stationEvaId":"493034",\n"boardType":"dep",\n"imgPath":"/hafas-res/img/",\n"iconProductsSubPath":"vs_oebb/",\n"rtInfo":true,\n"journey":[\n{"id":"4799968126","ti":"14:43","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"15:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968127","ti":"14:46","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"15:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968127","ti":"14:58","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"15:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437988810","ti":"15:00","da":"16.08.2022","pr":"Bus 646","st":"Meggenhofen","lastStop":"Meggenhofen Pendlerparkplatz","ati":"15:34","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968128","ti":"15:01","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"15:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968128","ti":"15:13","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"15:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968129","ti":"15:16","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"15:54","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968129","ti":"15:28","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"15:54","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437968810","ti":"15:31","da":"16.08.2022","pr":"Bus 646","st":"Wels Hbf via Krenglbach","lastStop":"Wels Hbf (Busterminal)","ati":"15:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968130","ti":"15:31","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"16:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968130","ti":"15:43","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"16:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968131","ti":"15:46","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"16:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968131","ti":"15:58","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"16:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437730810","ti":"16:00","da":"16.08.2022","pr":"Bus 646","st":"Kematen am Innbach","lastStop":"Kematen/Innbach Ortsmitte","ati":"16:26","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968132","ti":"16:01","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"16:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968132","ti":"16:13","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"16:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968133","ti":"16:16","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"16:54","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437853811","ti":"16:20","da":"16.08.2022","pr":"Bus 646","st":"Haag am Hausruck","lastStop":"Haag am Hausruck Bahnhofstraße","ati":"17:00","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437747810","ti":"16:23","da":"16.08.2022","pr":"Bus 646","st":"Wels Hbf via Krenglbach","lastStop":"Wels Hbf (Busterminal)","ati":"16:31","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968133","ti":"16:28","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"16:54","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968134","ti":"16:31","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"17:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968134","ti":"16:43","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"17:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968135","ti":"16:46","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"17:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968135","ti":"16:58","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"17:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437730811","ti":"17:00","da":"16.08.2022","pr":"Bus 646","st":"Kematen am Innbach","lastStop":"Kematen/Innbach Ortsmitte","ati":"17:26","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437937810","ti":"17:01","da":"16.08.2022","pr":"Bus 646","st":"Wels Hbf via Krenglbach","lastStop":"Wels Hbf (Busterminal)","ati":"17:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968136","ti":"17:01","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"17:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968136","ti":"17:13","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"17:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968137","ti":"17:16","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"17:54","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437850810","ti":"17:20","da":"16.08.2022","pr":"Bus 646","st":"Haag am Hausruck","lastStop":"Haag am Hausruck Bahnhofstraße","ati":"18:00","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968137","ti":"17:28","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"17:54","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968138","ti":"17:31","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"18:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968138","ti":"17:43","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"18:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968139","ti":"17:46","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"18:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968139","ti":"17:58","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"18:24","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437730812","ti":"18:00","da":"16.08.2022","pr":"Bus 646","st":"Kematen am Innbach","lastStop":"Kematen/Innbach Ortsmitte","ati":"18:26","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437968811","ti":"18:01","da":"16.08.2022","pr":"Bus 646","st":"Wels Hbf via Krenglbach","lastStop":"Wels Hbf (Busterminal)","ati":"18:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968140","ti":"18:01","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"18:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"4799968140","ti":"18:13","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"18:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"480049810","ti":"18:16","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Spöttlsiedlung","ati":"18:23","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"438083810","ti":"18:20","da":"16.08.2022","pr":"Bus 646","st":"Aistersheim","lastStop":"Aistersheim Kriegerdenkmal","ati":"18:50","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437750810","ti":"18:23","da":"16.08.2022","pr":"Bus 646","st":"Wels Hbf via Meggenhofen","lastStop":"Wels Hbf (Busterminal)","ati":"18:31","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"479592810","ti":"18:31","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"19:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"479592810","ti":"18:43","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"19:09","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437841810","ti":"19:00","da":"16.08.2022","pr":"Bus 646","st":"Meggenhofen","lastStop":"Aistersheim Kriegerdenkmal","ati":"19:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"479592811","ti":"19:01","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Machstraße","ati":"19:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"479592811","ti":"19:13","da":"16.08.2022","pr":"Bus 2","st":"Wels Ghegastraße","lastStop":"Wels Machstraße","ati":"19:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"437800810","ti":"19:31","da":"16.08.2022","pr":"Bus 646","st":"Wels Hbf via Krenglbach","lastStop":"Wels Hbf (Busterminal)","ati":"19:39","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"479964810","ti":"19:31","da":"16.08.2022","pr":"Bus 2","st":"Flemingstraße","lastStop":"Wels Kaiser-Josef-Platz (Busbahnhof)","ati":"19:49","tr":"","trChg":false,"rt":false,"rta":false} \n,{"id":"479964810","ti":"19:43","da":"16.08.2022","pr":"Bus 2","st":"Wels Kaiser-Josef-Platz","lastStop":"Wels Kaiser-Josef-Platz (Busbahnhof)","ati":"19:49","tr":"","trChg":false,"rt":false,"rta":false} \n],\n"maxJ":49\n}\n'