我想从此网页获取Date,Distance和Fin列:http://www.gbgb.org.uk/raceCard.aspx?dogName=Ballymac%20Monleek并在JavaFX的TableView中显示该数据。
如何使用jSoup选择指定的列,然后将这些列放入TableView?
我目前的代码只能抓住" Fin"该网页中的列 - 我发现很难弄清楚如何获取其他两列,然后我不确定如何将它们放入Observable List中以显示在Table View中。
Dog dog = (Dog)tblRunners.getSelectionModel().getSelectedItem();
String selectedDog = dog.getName();
//getHistory
String dogPage = "http://www.gbgb.org.uk/raceCard.aspx?dogName=" + selectedDog;
Document doc1 = Jsoup.connect(dogPage).get();
Element tblHeader = doc1.select("tbody").first();
for (Element element1 : tblHeader.children()){
String position = element1.select("td:eq(4)").text();
System.out.println("Position: " + position);
}
由于 罗布
答案 0 :(得分:0)
public class DogDetail {
private String date;
private String distance;
private String fin;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public String getFin() {
return fin;
}
public void setFin(String fin) {
this.fin = fin;
}
}
FXCollections.observableArrayList
函数来创建一个可观察列表。代码:Element tblHeader = doc1.select("table.MasterTable_Web20 tbody").first();
List<DogDetail> data = new ArrayList<>();
for (Element element1 : tblHeader.children()){
DogDetail dogDetail = new DogDetail();
dogDetail.setDate(element1.select("td:eq(0)").text());
dogDetail.setDistance(element1.select("td:eq(1)").text());
dogDetail.setFin(element1.select("td:eq(4)").text());
data.add(dogDetail);
}
TableView<DogDetail> table = new TableView<DogDetail>(FXCollections.observableArrayList(data));