Skip to content

Retrieving parent's next sibling? #188

Answered by christian-draeger
aaulia asked this question in Q&A
Discussion options

You must be logged in to vote

hey,
assuming you have a html snippet like this:

<p style="margin-bottom: 5px">
    <strong>Producer</strong>
    :
</p>
<p>
      Foo, Bar
</p>

you can do as follows to get the first sibling of the strongs parent element:

val firstSiblingOfStrongParent = htmlDocument(someHtmlSnippet) {
    strong {
        findFirst {
            parent {
                siblings[0]
            }
        }
    }
}

println(firstSiblingOfStrongParent.text) // will print:  Foo, Bar

with that

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by christian-draeger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants