Jsoup 在内部 div 中获取具有相同 class 名称的文本而不重复

Jsoup get text in the inner div with same class name without dupplicating

所以我需要在其中获取文本

<div class="posting">
    <div class="posting">
        <div class="posting">
            Sample Text
        </div>
    </div>
</div>

然而,查询 select("div.posting") returns 重复输出 like

Sample Text
Sample Text
Sample Text

我如何编写查询,使其只有 returns 个 Sample Text

select("div.posting div.posting div.posting");

应该适合你。它基本上告诉 JSoup 给你 div.posting 里面的 div.posting 又在 div.posting.

里面

编辑: 如果您的 div 被这样的 td.content 包围:

<td class="content">
    <div class="posting">
        <div class="posting">
            <div class="posting">
                Sample Text
            </div>
        </div>
    </div>
</td>

那么这段代码也应该可以工作,而且会更通用:

select("td.content > div.posting");

它选择 div.posting,它是 td.content 的直接子代。