【问题标题】:XPath using contains in this situation? [closed]在这种情况下使用包含的 XPath? [关闭]
【发布时间】:2012-07-05 19:52:26
【问题描述】:

HTML 中的情况:

<div class="someDivision">
   <span class="firstSpan">...</span>
   <span class="firstSpan">...</span>
   <span class="firstSpan">
      <span class="secondSpan">...</span>
      <span class="secondSpan">
         "Unique text"
         <a>"Text which I need"</a>

我需要访问 &lt;a&gt; 中包含的文本。

【问题讨论】:

  • 在主题线程中我写了 XPath

标签: text xpath contains html


【解决方案1】:

我不完全确定您在问什么,但如果是“我如何在 a 元素中获取文本,该元素前面是包含 "Unique text" 的文本节点,并且位于 span 元素中class 属性等于secondSpan,它本身位于span 元素内,class 属性等于firstSpan,它本身位于div 元素内,class 属性等于@ 987654331@?”那么这个 XPath 应该可以解决问题:

div[@class='someDivision']/span[@class='firstSpan']/span[@class='secondSpan']/a[contains(preceding-sibling::text(), '&quot;Unique text&quot;')]/text()

【讨论】:

  • 感谢您的回复。您的解决方案有效!
【解决方案2】:

使用

//div[@class='someDivision']
  /span[class='firstSpan']
    /span[class='secondSpan' and contains(text()[1], 'Unique text')]
      /a[1]
         /text()[1]

【讨论】:

    猜你喜欢
    • 2016-05-12
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2020-12-27
    • 1970-01-01
    • 2021-11-22
    相关资源
    最近更新 更多