dpauf28808 2016-08-04 23:13
浏览 49
已采纳

关闭标记后的XPath数据

I have this HTML: <span id="bla">text</span>more text

I want to get text and more text.

I have this XPath: //span[@id="bla"]/text()

I can't figure out how to get the closing tag and what comes after it.

  • 写回答

2条回答 默认 最新

  • dtvnbe1428 2016-08-04 23:18
    关注

    <span id="bla">text</span>more text alone is not well-formed and cannot be processed via XPath.

    Let's put it in context:

    <div><span id="bla">text</span>more text</div>
    

    Then, you can simply take the string value of the parent element, div:

    string(/div)
    

    to get

    textmore text
    

    as requested.


    If there's other surrounding content that you don't want:

    <div>DO NOT WANT<span id="bla">text</span>more text<b/>DO NOT WANT</div>
    

    You can follow @alecxe's lead with the following-sibling:: axis and use concat() to combine the parts you want:

    concat(//span[@id="bla"], //span[@id="bla"]/following-sibling::text()[1])
    

    to again get

    textmore text
    

    as requested.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀