Reputation: 10590
This is my HTML:
<tr>
<td bgcolor="ffffff" height="14" width="112"><p class="boldblack"> Price:</p></td>
<td bgcolor="ffffff" width="296"><p class="cena2">9 000 $</p></td>
<td bgcolor="ffffff"></td>
</tr>
I want to take the 9 000
.//p[contains(., 'Price:')]
which gives me the Price:
node. Now, how can I reach the 9000
from the Price
node?
I can't use XPath like td[2] because I am having a dynamic content. I just know that I will have the price
node and their parent's brother will have the 9000 $
Upvotes: 1
Views: 224
Reputation: 474221
One option would be to simply to rely on the class name (cena
from Russian is price
):
//p[@class="cena2"]/text()
If you want to rely on the preceding Price:
label:
//tr[td[1]/p[contains(., "Price:")]]/td[2]/p/text()
Another option would be to check whether the text ends with $
sign:
//tr/td/p[ends-with(., "$")]/text()
As you see, there are multiple options, it is hard to tell which one is more reliable since you haven't showed the complete HTML code. You can even combine all 3 options I've presented.
Upvotes: 2