使用 Xpath 获取 html 标记之前或之后的文本


Get text before or after html tags using Xpath

我有html,我在这里简化,我需要编写一个xPath来获取电话号码。

<td>
    <font>
        <b>
            <font size="2">
                <a href="#">Some link</a>
            </font>
        </b>
        <br>
        Abc Address
        <br>
        Country name
        <br>
        (123) 456-7890
        <hr>
        A sentence here..
        <img src="/images/abc.gif">
    </font>
</td>

我可以将锚标签内的文本提取为,

->filterXPath('//font//b//a')->extract('_text'); //returns some link

如何在最后一个<br>标签之后或第一个<hr>标签之前提取此文本 (123) 456-7890?我访问过此链接,但我无法正确理解。

我也试过这个:

->filterXPath('//font//br[last()]')->extract('_text'); // returns nothing but empty

选择最后一个br,然后选择其第一个文本同级:

//font/br[last()]/following-sibling::text()[1]