找到元素中元素的索引

时间:2013-07-23 23:29:33

标签: java jsoup

我正在尝试在Elements中找到Element的索引,这是它在commentNumber序列中的位置,它在之前的for循环中出现过。

    Elements comments = qaDoc.select("li[data-comment-id]");

    commentNumber = 0;

    for (Element comment : comments) {
        commentNumber = commentNumber + 1;

        reply = comment.select("a[class$=d2-in-reply-to]").first();
        replyToId = reply.attr("data-action-target");

        //How do you find the index of the following element??? Thanks
        comments.select("li[data-comment-id=" + replyToId + "]").first();
    }

如果有像

这样的方法
comments.select("li[data-comment-id=" + replyToId + "]").first().indexOf();

我需要导入什么才能访问它。我现在只编写java和jsoup一周了,还有很多东西需要学习。感谢

1 个答案:

答案 0 :(得分:0)

使用下面的分配,我能够解决问题。

replyToNumber = 1 + comments.indexOf(comments.select("li[data-comment-id=" + replyToId + "]").first());