【问题标题】:XPath query to get node after some other nodeXPath 查询以在其他节点之后获取节点
【发布时间】:2010-04-20 13:07:50
【问题描述】:

我正在使用“HtmlAgilityPack”来解析 HTML 内容。 我的目标是获得数值。

<div>
    some content 1
    <br>
    some <b>content</b> 2
    <br>
    <b>NUMBER:</b>
    9788492688647
    <br>
    some content 3
    <br>
    some content 4
    </div>


aim:
 - get "9788492688647"

Anybody can tell me how to get value between  /div/b[2] and <br> ?

【问题讨论】:

    标签: xml xpath html-agility-pack


    【解决方案1】:

    这应该可行:

    /div/b[2]/following-sibling::text()[1]
    

    但是,根据结构的一致性,您可能需要执行以下操作:

    /div/b[. = 'NUMBER:']/following-sibling::text()[1]
    

    【讨论】:

    • 第一个完美运行:),第二个抛出异常,语法不正确。非常感谢:),这就是我想要的。
    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    相关资源
    最近更新 更多