1
HTML結構:的Xpath正從平HTML層次元素
<div class="title">
<h1>Some title</h1>
</div>
<div class="row">something</div>
... (repeats the same structure)
<div class="title">
<h1>Another title</h1>
</div>
<div class="row anotherclass">1 something</div>
<div class="row">2 something</div>
<div class="row">3 something</div>
<div class="title">
<h1>Some title</h1>
</div>
<div class="row">something</div>
我怎樣才能得到所有的div(與 「行」 類「),其中一個標題(H1)符合我$search
我已經把現在(沒有爲最後一個元素工作,它也不會在下一標題停止):
//div[child::h1[contains(text(), "<?php echo $search ?>")]]
/following-sibling::div[contains(concat(" ", normalize-space(@class), " "), " title ")]
/preceding-sibling::div[contains(concat(" ", normalize-space(@class), " "), " row ")]
如果我搜索 「的另一個頭銜」,輸出應該是:
<div class="row anotherclass">1 something</div>
<div class="row">2 something</div>
<div class="row">3 something</div>