Question

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/

Was it helpful?

Solution 2

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.

OTHER TIPS

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().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top