0
$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');
}

Giving the error on $col1

I can get it working using this but you can't use break as it's not a real for loop

$crawler->filter('.row')->each(function (Crawler $row, $i) {
    $col1 = $row->filter('.col-md-3');
    $col2 = $row->filter('.col-md-9');
    ...
    ...
}
Jonathan
  • 3,016
  • 9
  • 43
  • 74

1 Answers1

4

The problem is that Crawler instances (stored in $rows, $reviewContent etc.) are iterated over their DOMElement contents. You can create a new Crawler instance within each loop step from that DOMElement, like this:

foreach ($rows as $domRow) {
  $row = new Crawler($domRow);
  // proceed as in the original code
}
raina77ow
  • 103,633
  • 15
  • 192
  • 229