Irwene
Irwene

Reputation: 3025

How to select text between two nodes

I'd like to select some text from a webpage using Xpath, but this text is between two nodes.

...
<table>
    <th>Abbreviation</th>
    <tr>
        <td>
            <span><u>General</u><br/></span>
            My Text <!--The text i want to get-->
            <br/><u>Def</u>
            Some other Text
       </td>
</table>
...

Please note that i can't alter the page since it's a source that i can't control.

I've already been through the W3C and wikipedia docs and dodn't found anything (or understood).

Thank you for your answers

Upvotes: 8

Views: 4842

Answers (1)

choroba
choroba

Reputation: 241748

You can use the following XPath expression. It searches for a span with a u child, then it selects the first following text.

//span[u]/following-sibling::text()[1]

Upvotes: 8

Related Questions