Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Text 在这种情况下使用包含的XPath?_Text_Xpath_Contains_Html - Fatal编程技术网

Text 在这种情况下使用包含的XPath?

Text 在这种情况下使用包含的XPath?,text,xpath,contains,html,Text,Xpath,Contains,Html,HTML中的情况: <div class="someDivision"> <span class="firstSpan">...</span> <span class="firstSpan">...</span> <span class="firstSpan"> <span class="secondSpan">...</span> <span clas

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>

...
...
...
“唯一文本”
“我需要的文本”

我需要访问

中包含的文本,我不完全确定您在问什么,但如果是“如何在
元素中获取文本,该元素前面有一个包含
唯一文本的文本节点?”“
并位于
span
元素内,该元素的
class
属性等于
secondSpan
,而该元素本身位于
span
元素内,该
class
属性等于
firstSpan
,它本身位于
div
元素中,其
class
属性等于
someDivision
?”那么这个XPath应该起到以下作用:

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

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

感谢您的回复。您的解决方案很有效!在我编写的主题线程中