import urllib3 def finde(s,f): index = s.find(f) if(index == -1): raise ValueError("Could not find") return(index) def getDate(s,e): s= s[finde(s,e)+len(e):] s= s[finde(s,"op"):] s= s[finde(s,"td")+1:] s= s[finde(s,"td")+1:] s= s[finde(s,">")+1:] t= s[:finde(s,"<")] datum = t.split(" ") #print(f"{e} op {datum[0]} {datum[1]} {datum[2]}") return(s,datum) stationWeb = {"bandijk" : "deventerijsselbrugwest", "utrechtcentraal" : "utrechtcs", } def stationInfo(name): if(name in stationWeb.keys()): name = stationWeb[name] user_agent = {'user-agent': 'agen'} http = urllib3.PoolManager(10,headers=user_agent) url = http.urlopen('GET',"https://www.stationsweb.nl"+name) s = str(url.data) #f = open("station.asp?station=bobeldijk") #s = f.read() #s= s[finde(s,"Geopend")+5:] openings = [] closings = [] try: (s,datum) = getDate(s,"Geopend") openings.append(datum) while(True): #s= s[finde(s,"Gesloten"):] (s,datum)= getDate(s,"Gesloten") closings.append(datum) (s,datum)=getDate(s,"Heropend") openings.append(datum) except: return((openings,closings)) #print(stationInfo("apeldoorn")) #stationInfo("voorst")