static public void main( String[] args ) {
Document playerpage =
Jsoup.connect("http://en.wikipedia.org/wiki/Diego_Forl%C3%A1n").get();
Elements table = playerpage.getElementsByTag("table").select("table.infobox");
Elements ind = table.select("tr:contains(Club information)");
如您所见,我成功选择了包含文字的表格行:Club information
。
如何返回此元素的行索引,因为我想使用该数字进行下一次搜索?
答案 0 :(得分:1)
Document playerpage = Jsoup.connect("http://en.wikipedia.org/wiki/Diego_Forl%C3%A1n").get();
Elements table = playerpage.select("table.infobox > tbody > tr");
int rowCount = 0;
for (Element e : table) {
if (e.text().contains("Club information")) {
System.out.println("Row: " + rowCount);
System.out.println(e);
}
rowCount++;
}