Java 在元素中查找元素的索引
我试图在元素中找到一个元素的索引,这是它在commentNumber序列中的位置,它在下面的for循环中出现过Java 在元素中查找元素的索引,java,jsoup,Java,Jsoup,我试图在元素中找到一个元素的索引,这是它在commentNumber序列中的位置,它在下面的for循环中出现过 Elements comments = qaDoc.select("li[data-comment-id]"); commentNumber = 0; for (Element comment : comments) { commentNumber = commentNumber + 1; reply = comment.s
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,还有很多东西要学。谢谢使用下面的作业,我能够解决这个问题
replyToNumber = 1 + comments.indexOf(comments.select("li[data-comment-id=" + replyToId + "]").first());
“commentNumber”有什么用?在我看来,这就是您要查找的索引(-1)?不,当前的commentNumber不是我要查找的,而是commentNumber或之前在循环中发生的回复的注释。无论如何,replyToNumber=1+comments.indexOf(comments.select(“li[data comment id=“+replyToId+”])).first();得到我需要的东西