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
Html 如何在一个查询中使用xpath在相似但略有不同的节点中获取值?_Html_Xpath - Fatal编程技术网

Html 如何在一个查询中使用xpath在相似但略有不同的节点中获取值?

Html 如何在一个查询中使用xpath在相似但略有不同的节点中获取值?,html,xpath,Html,Xpath,我想创建xpath查询,从link1和Link2获取url,并要求不更改结果中的顺序 First situation <div id="id"> <span class="class"> <a href=http://whatever.url>link 1</a> </span> </div> Second Situation <div id="id"> <span

我想创建xpath查询,从link1和Link2获取url,并要求不更改结果中的顺序

First situation
<div id="id">
    <span class="class">
        <a href=http://whatever.url>link 1</a>
    </span>
</div>
Second Situation
<div id="id">
    <span class="class anotherclass">
        <h5>
            <a href=http://whatever.url>link 2</a>
        </h5>
    </span>
</div>
(...Above situation can happen more times on site in any order...)

但是我不能让它工作。

像这样,在“变量”层次结构上使用//怎么样

div[@id='id']/span[@class]//a[@href]
div[@id='id']/span[@class]//a[@href]