XPath Select 基于子节点的父节点

XPath Select parent node based on child node

我需要提取其后代所在的 href:i/[@class="icon-right-open rotate180"]

我尝试了以下方法,但它对我不起作用

//a[@class="arrowDot "]/@href /descendant::i[@class="icon-right-open rotate180"]

这里是 HTML 代码:

<div class="paginationDots sMargTop centered">
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:2:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="arrowDot ">
        <i class="icon-left-open rotate180"/>
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="Dots ">
                        1
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:2:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="Dots ">
                        2
    </a>
    <a class="Dots currentDot">
                        3
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:4:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="Dots ">
                        4
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:5:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="Dots ">
                        5
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:6:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="Dots ">
                        6
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:7:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="Dots ">
                        7
    </a>
    <a href="https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:4:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale" class="arrowDot ">
        <i class="icon-right-open rotate180"/>
    </a>
</div>

预期结果如下URL: https://www.mubawab.tn/fr/cc/immobilier-a-vendre-all:p:4:sc:apartments-for-sale,commercial-property-for-sale,farms-for-sale,houses-for-sale,land-for-sale,villas-and-luxury-homes-for-sale 但实际输出为空

你几乎答对了。这是您需要的。

//a[@class="arrowDot "][descendant::i[@class="icon-right-open rotate180"]]/@href