I am new to XPath so I apologize if this is horribly easy (however couldn't find anything in search related to this specific process). I am using Xpath in google sheets to try and retrieve this information.
Example Code snippet to start:
<div class="product-grid-item card mb-4 shadow-sm">
<a href="/collections/available/products/blue" class="card-link"></a>
<div class="card-banner false"> </div>
<img src="//Blue_1_large.jpg?v=154" alt="Blue" class="card-img-top img-fluid">
<div class="card-body pt-0">
<div class="product-form-type mb-4 d-flex flex-direction-row flex-wrap">
<img src="37/assets/tsf-form-icon.svg?3" alt="Flower">
<p class="price">
<span class="range-price"><sup class="currency">$</sup>8<span class="d-none">.</span><sup>50</sup></span>
<small>/<span data-i18n="general.product.sellable_measures"></span></small></p>
</div>
<h4 class="card-title" data-i18n="general.product">
Blue
</h4>
<p class="card-text">
<small>8-11
</small>
<br>
<small>8-11
</small>
</p>
</div>
<div class="card-footer bg-transparent">
<hr>
<span class="range-price"><sup class="currency">$</sup>42<span class="d-none">.</span><sup>50</sup></span>
<span class="range-sep">–</span>
<span class="range-price"><sup class="currency">$</sup>122<span class="d-none">.</span><sup>50</sup></span>
<small>/<span data-i18n="general.product.sellable_measures"></span></small>
</div>
</div>
I am trying to figure out how to pull the href value (ex. ) but I need to check to make sure that the class is equal to "card-banner false" and return the href values that pass that check.
Currently I have: //div[contains(@class,'product-grid-item card mb-4 shadow-sm') and class = 'card-link']//a/@href
However that retrieves nothing, which I believe is because I need to use preceding, however I can't seem to get that to work.
I have confirmed that it can be read as //div[contains(@class,'card-banner false')]//@* does return the proper amount of instances. I just need to find the way to reference it properly.
Thanks!
答案 0 :(得分:1)
您可以使用preceding-sibling
选择上一个元素
//div[contains(@class,'card-banner false')]/preceding-sibling::a/@href