如何在Crawler中传递一个元素的每个函数?

时间:2016-03-25 18:04:23

标签: symfony web-crawler

我用Symfony的Crawler解析我的xml并且无法获得如何传递(换句话说继续)一个元素而不是将它包含在最终数组中?

例如:

$node->filterXPath('//ExampleNode')->each(function(Crawler $child, $i) {
    if (! count($child->filterXPath('//ChildNode'))) {
        continue;
    }

    return $child->filterXPath('//ChildNode')->text();
});

1 个答案:

答案 0 :(得分:1)

您可以使用Symfony\Component\DomCrawler\Crawler::reduce(Closure)

$crawler->reduce(function($result, $item) {
    $childNodes = $item->filterXPath('//ChildNode');

    if ($childNodes->count()) {
        $result[] = $item;
    }
});
相关问题