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

标签 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();
});

最佳答案

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

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

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

关于symfony - 如何在Crawler每个函数中传递一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36225365/

相关文章:

forms - 在表单或属性中定义日期步骤

php - 如何从 Controller Symfony2 内部访问不同的 Controller

python - 碎片 : preventive measures before running the scrape

html - 元关键字是否区分大小写?

php - Symfony 4 版本 :entity --regenerate fail with: No entities were found in the "App" namespace

php - 根据 Doctrine 中的条件更新某些字段

web-crawler - 如何设置只允许网站默认页面的robot.txt

jquery - googlebot 是否会抓取 jQuery $.get() 调用中的网址并且可以阻止吗?

javascript - 如何使用关键字搜索抓取 youtube 视频链接

symfony - 使用 Symfony2 管理用户/组对象权限的最佳方式