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,你好,我有这个HTML: <div class="_3Vhpd"><span>Your commerce Data</span> <a class="n3G0C" href='http://www.webadress.......'><span>Some Text</span</a> </div> 但我没有收到任何“[]”。可能是因为不只是在div之后,而是在span之后…首先,示例html没有class

你好,我有这个HTML:

<div class="_3Vhpd"><span>Your commerce Data</span>
<a class="n3G0C" href='http://www.webadress.......'><span>Some Text</span</a>
</div>

但我没有收到任何“[]”。可能是因为不只是在div之后,而是在span之后…

首先,示例html没有
class=“n3G0C”
,但是假设您修复了它,这个xpath表达式应该可以工作:

//div[contains(@class,"_3Vhpd")]//following-sibling::a/@href
输出:


我已经修改了原来的帖子仍然不工作,返回[]。。。即使元素不是div后面的下一个元素,我也可以使用下面的同级元素吗?使用child::而不是下面的同级元素working@bartoro-如果它在实际html上是这样工作的,那么只需使用
//div[contains(@class,“\u 3Vhpd”)]//a/@href
。您可能会说您收到了一个空数组。请把你的问题说得更清楚,这样你就更有可能得到更好的答案。
//div[contains(@class,"_3Vhpd")]//following-sibling::a/@href