Reputation: 609
I am trying to get these two attributes separately. When I try to get the version class the duration also gets lumped in with it as the tag is not closed. Also if there happens to be no version then I'd just get the duration returned. How do I ensure I grab this data separately and correctly?
Here's the html:
<span class="version">Original Version <span class="duration">(6:20)</span></span>
This is my current code and also the results I get now:
.//span[@class='duration'] Result: "(6:20)" CORRECT
.//span[@class='version'] Result: "Original Version (6:20)" INCORRECT!
I tried playing around with the 'not contains' operator but still cannot figure it out. Thanks for any help in advance.
Upvotes: 0
Views: 81
Reputation: 122364
This might be one of the few valid use cases for text()
:
.//span[@class='version']/text()
would give you just text nodes that are direct children of the version
span, and not the text contained in any child elements.
In your example you'd get one text node whose value is "Original Version " (including a trailing space).
Upvotes: 1