Bartek Bartek - 1 month ago 6
Java Question

Java - getting data from website using Jsoup?

How get selected data (screen - Total shoots) from website using jsoup?

HTML code screen

try {
final Document document = Jsoup.connect("www...").get();
for (Element row : document.select("div#in-game-stats")) {
System.out.println(row.select(" .si-title").text());
}
} catch (IOException e) {
e.printStackTrace();
}

Answer

If you only need the title try:

try {
    final Document document = Jsoup.connect("www...").get();
    for (Element row : document.select("div#si-title")) {
        System.out.println(row.text());
    }
} catch (IOException e) {
    e.printStackTrace();
}

If you need more values of the stat-item try this:

try {
    final Document document = Jsoup.connect("www...").get();
    for (Element statItem : document.select("div#stat-item")) {
        for (Element child : statItem.children()) {
            System.out.println(child.attr("class") +" = " +child.text());   
        }
    }
} catch (IOException e) {
    e.printStackTrace();
}