【发布时间】:2020-03-03 07:36:21
【问题描述】:
我想从 jsoup 的嵌套 href 中检索数据,我的意思是: 我有href: https://www.sherdog.com/news/rankings/2/Sherdogs-Official-Mixed-Martial-Arts-Rankings-164999
我想从这 10 位选手中获取每个数据,例如:
1。 菌种 年龄:37 要么 协会: 强大的风格战斗团队
2。 丹尼尔·科米尔 年龄:40 要么 协会: 美国跆拳道学院
等等。
如何做到这一点?
String url = "https://www.sherdog.com/news/rankings/2/Sherdogs-Official-Mixed-Martial-Arts-Rankings-164999";
Document document = Jsoup.connect(url).get();
Elements allH1 = document.select("h2");
for (Element href : allH1) {
Elements allAge = document.select("div.birth_info");
for (Element age : allAge) {
System.out.println(href.select("a[href]").text().toString());
System.out.println(age.select() // something there?);
}
【问题讨论】: