小编jmo*_*ris的帖子

DOM 帮助 - jsoup nextSibling

我想要做的事情对我来说似乎很简单,但我的挣扎远比我应该的要多。我有一个包含以下内容的文档:

<h2>First Heading</h2>
<table>
    <div class="title">First Subheading One</div>
    <div class="title">First Subheading Two</div>
    <div class="title">First Subheading Three</div>
</table>

<h2>Second Heading</h2>
<table>
    <div class="title">Second Subheading One</div>
    <div class="title">Second Subheading Two</div>
    <div class="title">Second Subheading Three</div>
</table>

<h2>Third Heading</h2>
<table>
    <div class="title">Third Subheading One</div>
    <div class="title">Third Subheading Two</div>
    <div class="title">Third Subheading Three</div>
</table>
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,使用 doc.select("h2") 给了我所有的标题。使用 doc.select("div.title") 给了我所有的副标题,正如预期的那样。我想要做的是遍历返回的 h2 元素,然后在其中遍历返回的 div.title 元素 - 我已经尝试了很多东西,而且我根本不熟悉编码(jsoup 的新手) ,但是)但我似乎无法理解如何做到这一点。

Headings = httpDoc.select("h3");
for(Element Headings : heading) {
    // something with heading.nextSibling here
}
Run Code Online (Sandbox Code Playgroud)

是否应该有什么我可以做的事情(例如 nextSibling)给我节点?从那里我可以做另一个 select("div.title") 并遍历那些以获取副标题? …

jsoup

2
推荐指数
1
解决办法
4804
查看次数

标签 统计

jsoup ×1