[英]Attempted to call an undefined method named “filter” of class “DOMElement”
$goutte = new GoutteClient();
$crawler = $goutte->request('GET', 'https://www.website.com');
$reviewContent = $crawler->filter('.review-content');
$rows = $reviewContent->filter('.row');
foreach ($rows as $row) {
$col1 = $row->filter('.col-md-3');
$col2 = $row->filter('.col-md-9');
}
在$col1
上给出错误
我可以使用它来工作,但您不能使用break
因为它不是真正的for loop
$crawler->filter('.row')->each(function (Crawler $row, $i) {
$col1 = $row->filter('.col-md-3');
$col2 = $row->filter('.col-md-9');
...
...
}
问题在于,对Crawler
实例(存储在$rows
, $reviewContent
等中)对其DOMElement内容进行了迭代。 您可以在每个DOMElement
循环步骤中创建一个新的Crawler
实例,如下所示:
foreach ($rows as $domRow) {
$row = new Crawler($domRow);
// proceed as in the original code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.