Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select text between two nodes

Tags:

xpath

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

like image 220
Sidewinder94 Avatar asked Apr 04 '13 14:04

Sidewinder94


1 Answers

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]
like image 107
choroba Avatar answered Nov 25 '22 23:11

choroba