Java - 使用Jsoup从网站获取数据?

时间:2016-10-26 11:04:41

标签: java jsoup

如何使用jsoup从网站获取所选数据(屏幕 - 总拍摄数量)?

HTML structure

更新了代码(仍未返回预期值):

try {
    final Document document = Jsoup.connect("https://www.betfair.com/exchange/plus/#/football/market/1.127737590").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();
}

1 个答案:

答案 0 :(得分:0)

如果您只需要标题,请尝试:

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();
}

如果您需要stat-item的更多值,请尝试以下操作:

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();
}