XPath gets text from an item after a specific item

So, if I have something like this:

//div[@class='artist']/p[x]/text()

x can be either 3, or 4, or even another number. Fortunately, if what I'm looking for is not at 3, I can just check the null value and continue until I find the text. The problem is that I would rather know that every time I am going to the right element. So I tried this:

div[@class='people']/h3[text()='h3 text']/p/text()

since after <h3>h3 text</h3>will always be <p>. However, this never returns anything and usually results in an error. If I remove / p, I get the text "h3 text".

Anyway, how do I get <p>directly after <h3>?

By the way, I am using HTMLCleaner in Java for this.

+5
source share
2

, , child::, / DOM . child::.

<div>, . - . , following-sibling::.

div[@class='people']/h3[text()='h3 text']/following-sibling::p/text()

XPath

Axes - XPath. , XPath .

, , , : @ attribute::. @href, attribute::href, , "href", .

, ? , ? , ? OK!

  • . .. self::node() parent::node(), . , .

  • //, //p body//a, descendant-or-self::node() . //p /descendant-or-self::node()/p.

+10

, <p> <h3>?

div[@class='people']/h3[text()='h3 text']/following-sibling::p[1]
+1

All Articles