【发布时间】:2021-05-29 14:19:52
【问题描述】:
我使用以下 xpath 查询来获取文本,但它从两者中获取文本,我只需要从每个组的第一个价格实例中获取它,页面上有几个组,所以我无法限制它。
有没有办法限制它,所以我只用一个类来获得跨度?
$prices = $xpath->query('//span[@class="a-price"]/span');
<div>
<span class="price">
text. <---This is the one I need
<span>
<span class="price red">
text
<span>
</div>
blah blah blah
<div>
<span class="price">
text. <---This is the one I need
<span>
<span class="price red">
text
<span>
</div>
blah blah blah
<div>
<span class="price">
text. <---This is the one I need
<span>
<span class="price red">
text
<span>
</div>
【问题讨论】: