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
Xpath同级文本_Xpath - Fatal编程技术网

Xpath同级文本

Xpath同级文本,xpath,Xpath,我想弄明白这件事已经有一段时间了,但我的头脑还是绕不过去。我尝试过使用跟随兄弟姐妹,但对我来说不起作用。这些类在所有方面都是通用的。我试图使用标记中的文本来识别然后提取兄弟内容: <div class="generic-class"> <p class="generic-class2"> <strong>Content title</strong> "

我想弄明白这件事已经有一段时间了,但我的头脑还是绕不过去。我尝试过使用
跟随兄弟姐妹
,但对我来说不起作用。这些类在所有方面都是通用的。我试图使用
标记中的文本来识别然后提取兄弟内容:

<div class="generic-class">
    <p class="generic-class2">
        <strong>Content title</strong>
        "
                              Dont Need                           "
        <br>
    </p>
</div>
<div class="generic-class">
    <p class="generic-class2">
        <strong>Content title2</strong>
        "
                              Needed Content                              "
        <br>
    </p>
</div>
<div class="generic-class">
    <p class="generic-class2">
        <strong>Content title3</strong>
        "
                              Dont Need                           "
        <br>
    </p>
</div>
<div class="generic-class">
    <p class="generic-class2">
        <strong>Content title4</strong>
        "
                              Dont Need                           "
        <br>
    </p>
</div>
有没有办法在
标记“Content title2”中查找文本,然后在父级中获取文本


任何帮助都将是惊人的,谢谢

这个应该返回
“需要的内容”


段落的文本(例如,
“所需内容”
)实际上是
strong
节点的同级。您当前的XPath是否没有得到任何输出或没有得到您想要的结果?我正在使用Chrome XPath扩展进行测试并给出结果(1),但在文本方面没有任何结果。我不信任所有这些Chrome XPath扩展…:)你在真实代码中尝试过XPath吗?我尝试过,我只是得到了一个空白结果。和AnderssonI给出的另一个表达式一样,我也注意到你是同一个人哈,我实现你给定答案的方式有问题,我弄乱了真正的xpath。现在开始工作了,非常感谢!
normalize-space(//*[@class="generic-class"]/p/strong/following-sibling::text())
normalize-space(//p/strong[.="Content title2"]/following-sibling::text())