我正在嘗試在以下結構中選擇特定型別的所有第一次出現:
<div class="jobs-list">
<div class="job-listing">
<h3>Title1</h3>
<span class="organization">
<a href="https://www.domain1.org/" target="_blank">Org1</a>
</span>
<span class="location">Loc1</span>
<div class="description">
desc1
<a href="https://www.domain1-1.org/" target="_blank">https://www.domain1-1.org/</a>
<span class="list-date">Posted on: 01/19/2022</span>
</div>
</div>
<div class="job-listing">
<h3>Title2</h3>
<span class="organization">
<a href="https://www.domain2.org/" target="_blank">Org2</a>
</span>
<span class="location">Loc2</span>
<div class="description">
desc2
<a href="https://www.domain2.org/" target="_blank">https://www.domain2.org/</a>
<span class="list-date">Posted on: 01/18/2022</span>
</div>
</div>
<div class="job-listing">
<h3>Title3</h3>
<span class="organization">
<a href="https://www.domain3.org/" target="_blank">Org3</a>
</span>
<span class="location">Loc3</span>
<div class="description">
desc3
<a href="mailto:[email protected]">[email protected]</a>
<span class="list-date">Posted on: 01/19/2022</span>
</div>
</div>
<div class="job-listing">
<h3>TItle4</h3>
<span class="organization">Org4</span>
<span class="location">Loc4</span>
<div class="description">
desc4
<a href="mailto:[email protected]">[email protected]</a>
<a href="https://www.domain4.org/" target="_blank">https://www.domain4.org/</a>
<a href="https://www.domain4-1.org/" target="_blank">https://www.domain4-1.org/</a>
<span class="list-date">Posted on: 01/06/2022</span>
</div>
</div>
</div>
具體來說,我需要結果如下:
https://www.domain1.org/
https://www.domain2.org/
https://www.domain3.org/
https://www.domain4.org/
which 應該是a/@hrefeach 下的第一個div[@class='job-listing'],但我不知道如何表達。需要注意的一些事項:
<a>始終是根下的兩個節點(作業串列)- 第一個
<a>并不總是正確的(只尋找http),但我可以很容易地過濾掉它們;我知道如何選擇節點,而不是過濾內容或類似的東西。 - 我需要 的值
a/@href,而不是 的內容<a>。
謝謝!
uj5u.com熱心網友回復:
//div[@class='job-listing']/descendant::a[1]為您a提供每個 s 的第一個后代div,如果您想添加檢查,請使用 eg //div[@class='job-listing']/descendant::a[starts-with(@href, 'http')][1]。
如果您需要href屬性節點,請使用//div[@class='job-listing']/descendant::a[starts-with(@href, 'http')][1]/@href. 請注意,XSLT 或 XQuery 的某些默認序列化不允許您序列化一系列獨立屬性節點,但在 XPath 2 或 3 中,您當然可以使用例如//div[@class='job-listing']/descendant::a[starts-with(@href, 'http')][1]/@href/string()來獲取一系列屬性值。
uj5u.com熱心網友回復:
我建議使用更多基于類的選擇器:
//span[@class="organization"]//a/@href
|
//div[@class="description"][not(preceding-sibling::span/a)]
//a[contains(@href,"http")][1]/@href
選擇organization( A)下的鏈接和不符合的第一個http鏈接descriptionA
查看
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/416450.html
標籤:
下一篇:如何擁有一個包含產品ID的鏈接
