17
17
18
18
# URL templates fuer den Scraper
19
19
URL_TEMPLATES = {
20
- "station_details" : "/german/hst /overview/{station_id:d}/" ,
21
- "line_details" : "/german/hst /showline/{station_id:d}/{line_id:d}/" ,
22
- "schedule_table" : "/german/hst /aushang/{station_id:d}/" ,
23
- "schedule_pocket" : "/german/hst /miniplan/{station_id:d}/" ,
20
+ "station_details" : "/haltestellen /overview/{station_id:d}/" ,
21
+ "line_details" : "/haltestellen /showline/{station_id:d}/{line_id:d}/" ,
22
+ "schedule_table" : "/haltestellen /aushang/{station_id:d}/" ,
23
+ "schedule_pocket" : "/haltestellen /miniplan/{station_id:d}/" ,
24
24
"departures" : "/qr/{station_id:d}/"
25
25
}
26
26
@@ -49,7 +49,7 @@ def get_stations():
49
49
Ruft Liste aller Stationen ab und gibt
50
50
Dict mit ID als Schlüssel und Name als Wert aus.
51
51
"""
52
- url = "http ://www.kvb-koeln.de/german/hst /overview/"
52
+ url = "https ://www.kvb.koeln/haltestellen /overview/"
53
53
r = requests .get (url , headers = HEADERS )
54
54
soup = BeautifulSoup (r .text )
55
55
#print(soup.prettify())
@@ -80,15 +80,15 @@ def get_station_details(station_id):
80
80
"""
81
81
Liest Details zu einer Station.
82
82
"""
83
- url = "http ://www.kvb-koeln.de/german/hst /overview/%d/" % station_id
83
+ url = "https ://www.kvb.koeln/haltestellen /overview/%d/" % station_id
84
84
r = requests .get (url , headers = HEADERS )
85
85
soup = BeautifulSoup (r .text )
86
86
details = {
87
87
"station_id" : station_id ,
88
88
"name" : stations [station_id ],
89
89
"line_ids" : set ()
90
90
}
91
- div = soup .find ("div " , class_ = "fliesstext " )
91
+ div = soup .find ("ul " , class_ = "info-list " )
92
92
for a in div .find_all ("a" ):
93
93
href = a .get ("href" )
94
94
if href is None :
@@ -107,7 +107,7 @@ def get_line_details(station_id, line_id):
107
107
"""
108
108
Findet heraus, welche Stationen eine Linie anfährt
109
109
"""
110
- url = "http ://www.kvb-koeln.de/german/hst /showline/%d/%d/" % (
110
+ url = "https ://www.kvb.koeln/haltestellen /showline/%d/%d/" % (
111
111
station_id , line_id )
112
112
r = requests .get (url , headers = HEADERS )
113
113
soup = BeautifulSoup (r .text )
@@ -118,8 +118,14 @@ def get_line_details(station_id, line_id):
118
118
"stations_reverse" : []
119
119
}
120
120
station_key = "stations_forward"
121
+ count = 0
121
122
for td in soup .find_all ("td" , class_ = re .compile (".*station" )):
122
123
tdclass = td .get ("class" )[0 ]
124
+ if tdclass == u'station-top' :
125
+ count = count + 1
126
+ if count == 2 :
127
+ station_key = "stations_reverse"
128
+
123
129
a = td .find ("a" )
124
130
if a is None :
125
131
continue
@@ -132,21 +138,19 @@ def get_line_details(station_id, line_id):
132
138
if result is None :
133
139
continue
134
140
details [station_key ].append (int (result ["station_id" ]))
135
- if tdclass == u'btstation' :
136
- station_key = "stations_reverse"
137
141
return details
138
142
139
143
140
144
def get_departures (station_id ):
141
145
"""
142
146
Aktuelle Abfahrten von einer Station laden
143
147
"""
144
- url = "http ://www.kvb-koeln.de /qr/%d/" % station_id
148
+ url = "https ://www.kvb.koeln /qr/%d/" % station_id
145
149
r = requests .get (url , headers = HEADERS )
146
150
soup = BeautifulSoup (r .text )
147
- tables = soup .find_all ("table" , class_ = "qr_table " )
151
+ tables = soup .find_all ("table" , class_ = "display " )
148
152
departures = []
149
- for row in tables [1 ].find_all ("tr" ):
153
+ for row in tables [0 ].find_all ("tr" ):
150
154
tds = row .find_all ("td" )
151
155
(line_id , direction , time ) = (tds [0 ].text , tds [1 ].text , tds [2 ].text )
152
156
line_id = line_id .replace (u"\xa0 " , "" )
0 commit comments