0
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

当我想使用该数字进行下一次搜索时,如何返回该元素的行索引?

4

1 回答 1

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++;
    }
于 2012-05-24T12:30:07.210 回答