【发布时间】:2016-06-10 08:17:51
【问题描述】:
有HTML之类的
<h3>Specifications</h3>
<div class="row"> some text </div>
<div class="row"> some text 2 </div>
<div class="row"> some text 3 </div>
<div class="detail-anchor" id="pricing"></div>
<div class="row"> some text 4</div>
我正在使用 PHP + phpQuery 来抓取网站
我只想获得前 3 个 div,换句话说,我想获得所有连续的 div.row。
这是我正在使用的代码
foreach (pq('h3:contains("Specifications")', $profile_page)->nextAll('div.row') as $div) {
}
但它的作用是,它也会刮掉some text 4 div。
我也尝试过nextAll('div.row'),但结果相同。
所以我的问题是,我如何在<h3>Specifications</h3> 之后获得所有连续的div.row,如果中间有任何其他标签,那么就停止。
PS:
纯 jQuery 的答案也将被接受,因为 phpQuery 库使用与 jQuery 相同的功能。
【问题讨论】: