0

I've been experimenting with ScraperWiki and yesterday, I could get a list of all lis in the DOM. Now, however, I only run through one iteration.

This is my code

$html = 'www.blah...'
$dom = new simple_html_dom();
$dom->load($html);
print_r('Starting parse');
$events = $dom->find("ul.listing li");
print_r('Found '.count($events).' events'); // shows there are 26 nodes
foreach($events as $data){
 // perform some processing then print to the console

I'm not really a PHP guy so I may be missing something obvious. The full source is at https://scraperwiki.com/scrapers/days_of_the_year/

Echilon
  • 10,064
  • 33
  • 131
  • 217
  • `print_r` is for printing arrays and objects, don't use it to print strings. Try using `print_r($events)` to see what the structure of `$events` is. – MrCode Mar 06 '12 at 08:52

2 Answers2

1

In the linked source, the foreach loop is different:

foreach($events->find('li.listPost') as $data) {
    // ...
}

This would seem to indicate that $events is a custom object, and cannot be looped through without some kind of getter such as find().

Luke Dennis
  • 14,212
  • 17
  • 56
  • 69
  • But if I extrapolate the `find` out, I get 26 nodes, yet the line printed in each iteration is only printed once. – Echilon Mar 06 '12 at 09:20
1

How very clumsy of me. I was missing the fact that the output was truncated after one line in the console. I added a linebreak and now get the expected output.

Echilon
  • 10,064
  • 33
  • 131
  • 217