Created
March 8, 2020 17:45
-
-
Save IT-Berater/70972029f0aa0ab187bda52d454e5982 to your computer and use it in GitHub Desktop.
Corona - Covid-19 from RKI
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
import java.io.IOException; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.nodes.Element; | |
import org.jsoup.select.Elements; | |
/** | |
* Beispiel Abfrage Coronavirus vom RKI. | |
* | |
* COVID-19: Fallzahlen in Deutschland | |
* | |
* https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html | |
* | |
* @author Thomas Wenzlaff | |
*/ | |
public class RkiCoronaFallzahlenDeutschland { | |
/** URL des RKI. */ | |
private static final String URL = "https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html"; | |
/** | |
* Start der Abfrage. | |
* | |
* @param args keine | |
* @throws IOException bei Lesefehler. | |
*/ | |
public static void main(String[] args) throws IOException { | |
Document doc = Jsoup.connect(URL).get(); // hole die ganze Seite aus dem Internet vom RKI | |
Element tabelle = doc.select("table").get(0); // das ist die erste Tabelle auf der Seite | |
Elements zeilen = tabelle.select("tr"); // selektieren aller Zeilen | |
for (Element zeile : zeilen) { // jede Zeile bearbeiten | |
Elements eintrag = zeile.select("td"); // hole die erste Zeile der Tabelle | |
if (!eintrag.isEmpty()) { // die Tabelle hat eine Leerzeile am Anfang, die überspringen wir | |
String bundesland = eintrag.get(0).text(); // das Bundesland holen, das ist der erste Eintrag in der ersten Spalte | |
String fälle = eintrag.get(1).text(); // die Anzahl der Fälle holen, das ist der Eintrag in der zweiten Spalte | |
System.out.println(bundesland + ", " + fälle); // Ausgabe im CSV-Format: Bundesland , Fälle | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment