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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改