JSoup解析:获取下一个元素

sup*_*ser 5 html android jsoup

我四处搜索,我找不到办法做到这一点.我有一组元素.我从这个组中选择一个元素.如何找到所选元素后面的下一个元素?

Dan*_*l B 15

使用该方法nextElementSibling().

例:

<body>
    <p>First in family!</p>
    <p>Second in family!</p>
    <p>Third in family!</p>
</body>
Run Code Online (Sandbox Code Playgroud)

Jsoup:

Element firstParagraph = doc.select("p:eq(0)").first();
Element secondParagraph = firstParagraph.nextElementSibling();

System.out.println(firstParagraph.text() + " " + secondParagraph.text());
Run Code Online (Sandbox Code Playgroud)

输出:家庭第一!家庭第二!