Search code examples
domxpathdomxpath

Match string and extract outside element?


Sample:

<div class="luikang">
    <p>Lui Kang information:<br><br>

        <strong>First game:</strong> Mortal Kombat (1992)<br>
        <strong>Created by:</strong> John Tobias<br>
        <strong>Orgin:</strong> Earthrealm<br>
        <strong>Weapon:</strong> Nunchaku<br>
        <strong>Colour:</strong> Red</p>
</div>

I would like to extract Nunchaku

My try so far:

/html/body//div[@class='luikang']/p/strong[contains(., 'Weapon:')]

I am guessing I need to use this too:

[count(preceding-sibling::br) < 1]

Any suggestion?


Solution

  • Try /html/body//div[@class='short_description']/p/strong[contains(., 'Weapon:')]/following-sibling::text()[1].