Created
October 31, 2013 11:46
-
-
Save hronecviktor/7248354 to your computer and use it in GitHub Desktop.
backup_mhdget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
from collections import namedtuple as nt | |
import re | |
import requests | |
vych = "Damborskeho" | |
cielova = "Trhovisko" | |
r = requests.get("http://imhd.zoznam.sk/ba/planovac-cesty-vyhladanie-spojenia.html?spojenieodkial="+vych+"&spojeniekam="+cielova) | |
data = r.text | |
soup = BeautifulSoup(data) | |
tables = soup.getText().split("Spojenie") | |
tables[7]=tables[7].split("◄")[0] | |
tables=tables[3:8] | |
print(tables[0]) | |
casy = re.findall("[\\d]{2}:[\\d]{2} [^-(\\s]*",tables[0]) | |
Spoj=nt("Spoj","casy nody") | |
Casy=nt("Casy","zaciatok koniec dlzka") | |
Noda=nt("Noda","prva nastup posledna vystup prestup") | |
Prestup=nt("Prestup","vychodzia cielova cas") | |
cas1=Casy("zaciatok","koniec",None) | |
spoj1=Spoj(cas1,"nejakenody") | |
print(spoj1.casy,"\t",spoj1.nody) | |
prvybus = re.findall("[\\w]{1,4}",tables[0].split("►")[0][-4:]) | |
print("prvybus: ",prvybus) | |
druhybus = re.findall("N?[1-9][\\d]{0,2}",tables[0].split("►")[1][-4:]) | |
print("druhybus: ",druhybus) | |
zastPrvySpoj=re.findall("(\\d{2}:\\d{2}[\\w ]+?)(zón|\\d|NA)",tables[0].replace(u'\xa0',u' ').split("►")[1]) | |
zastPrvySpoj=[y[0].strip() for y in zastPrvySpoj] | |
zastavky=[] | |
zastavky.append([]) | |
for y in zastPrvySpoj: | |
x=y | |
if y[5]!=" ": | |
x=y[:5] | |
x+=" " | |
x+=y[5:] | |
zastavky[0].append(x) | |
zastDruhySpoj=re.findall("(\\d{2}:\\d{2}[\\w ]+?)(zón|\\d|NA)",tables[0].replace(u'\xa0',u' ').split("►")[2]) | |
zastDruhySpoj=[y[0].strip() for y in zastDruhySpoj] | |
zastavky.append([]) | |
for y in zastDruhySpoj: | |
x=y | |
if y[5]!=" ": | |
x=y[:5] | |
x+=" " | |
x+=y[5:] | |
zastavky[1].append(x) | |
print(zastavky) | |
presun = re.findall("Presun.+?min",tables[0]) | |
print("presun:",presun) | |
celk_cas = re.findall("\(.+?\)",tables[0])[0].replace(u'\xa0', u' ') | |
print("celk.cas: ",celk_cas) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment