首页 > 解决方案 > 项目的刮板循环,如果它是空的则跳过

问题描述

我有一个小问题,我需要你的指导。

我正在尝试使用包含<a>标签的项目列表来抓取页面。现在<a>,其中一些项目中缺少标签,并且它返回了一条错误消息:

The current node list is empty.

这是我的代码:

$datas = $mainPage->filter('#accordion div')->each(function($item){
        return $results[] = $item->filter('table tr td')->each(function($data, $i) { 
            $re2[$i] = $data->filter('a')->text();
            //I need it to skip when **[a][1]** tag doesn't exist and continue looping
        });
});

这是页面项目的视图:

图片

标签: phpscreen-scraping

解决方案


推荐阅读