Using XPath: how to exclude text in nested elements
if i have some kind of html like following
<div class=unique_id> <h1 class="parseasinTitle"> <span> Game Title </span> </h1> Game Developer </div> Is there a way I can use xpath to get ONLY the “Game Developer” part in the text? From the search, I tried:
//div[@class='unique_id' and not(self::h1/span)] But it still gives me the whole text of "Game Game Game Developer".
The conditions in square brackets (“predicate”) determine the conditions for the node. div node is not h1 at the same time, so negation is done. But if you used child instead of self , which was probably your original intention, you would not get the expected text - you would not get anything, because it means: "Searching for a div with a unique id of tah does not have h1 / span child".
If you want text, specify the text ():
//div/text()[last()]