XPATH-如果找到某些类,则在div中获取URL

时间:2019-07-25 06:57:10

标签: xpath

<a class="card item" href="symatic-darcy-d/cadence-with-rhythm-%26-flow-%5B7%22%5D/CNP003-7inch" title="Symatic / Darcy D - Cadence With Rhythm &amp; Flow [7&quot;]">
<img class="lazy" src="thumb.png?CNP003-7inch" data-original="thumb.png?CNP003-7inch" alt="CNP003-7inch.png" style="display: block;">
<noscript><img src="thumb.png?CNP003-7inch" alt="CNP003-7inch.png" /></noscript>
<span class="artist">Symatic / Darcy D</span>
<span class="title">Cadence With Rhythm &amp; Flow [7"]</span>
<span class="description">"Combinations with Rhythm and Flow" is our first 7" skipless scratch tool created with portable scratching in mind.
 Featuring skip proof loops from "Combinations from the Masters" and "Cadence with Rhythm and Flow" portable scratchers have two scratch records in one re-configured to a pitch that works perfectly with portable set-ups.
 Side A - 83.33 BPM @ 33 1/3 RPM - Cadence with Rhythm and Flow
 Side B - 83.33 BPM @ 33 1/3 RPM - Combinations from the Masters
 Each side has 10 tracks of samples and a full sentence + bass tone and drums.</span>
<span class="ilabel">Cut &amp; Paste</span>
<span class="formats">7"</span>
</a>

我试图获取这些URL,但前提是格式为7"

所以在这种情况下,我想返回:

symatic-darcy-d/cadence-with-rhythm-%26-flow-%5B7%22%5D/CNP003-7inch

我可以得到7英寸的钻头,但是却不能抓住href。

//span[@class='formats'][contains(., '7"')]/parent::a/following-sibling::href/

1 个答案:

答案 0 :(得分:0)

请尝试使用xpath作为

//span[@class='formats'][contains(., '7"')]//ancestor::a

然后尝试使用与您用于自动化的语言等效的get_attribute来获取href。