You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB
Python

from bs4 import BeautifulSoup
import datetime
import requests
URLS = [
"https://www.hnd.bayern.de/pegel/inn/laufen-siegerstetter-keller-18602009/tabelle?methode=wasserstand&setdiskr=15",
"https://www.hnd.bayern.de/pegel/inn/laufen-siegerstetter-keller-18602009/tabelle?methode=abfluss&"]
def convert_to_datetime(datum):
if datum is not None:
datum = datetime.datetime.strptime(datum.get_text(), "%d.%m.%Y %H:%M")
return datum
def convert_to_value(messwert):
if messwert is not None:
messwert = messwert.get_text()
if "-" not in messwert:
messwert = float(messwert.replace(",", "."))
else:
messwert = None
return messwert
def scrap_messwerte(url):
r = requests.get(url)
soup = BeautifulSoup(r.text, features="html5lib")
return soup
def scrap_messwerte_hnd(url):
soup = scrap_messwerte(url)
el = (
soup.find_all("tr")
)
datensaetze = []
for a in el:
messwert = convert_to_value(a.find("td", {"class": "center"}))
datum = convert_to_datetime(a.find("td"))
if messwert is not None and datum is not None:
datensaetze.append([datum, messwert])
return datensaetze
def main():
for url in URLS:
datensatz = scrap_messwerte_hnd(url)
pass
if __name__ == "__main__":
main()