1

Get child node based on a specific parent

function(Crawler $node,){
    $node->filter('this>ul');
}

How can I get a $node children,that does not contain a grandson like the CSS selector #parent>child ?

perror
  • 7,071
  • 16
  • 58
  • 85
韩川川
  • 11
  • 4

1 Answers1

2
  1. You are using CSS selector.
  2. There aren't any this or parent selector in CSS.
  3. You should use just $node->filter('>ul');
michail_w
  • 4,318
  • 4
  • 26
  • 43
  • 1
    I tried, no good; error:Expected selector, but " at 0> found. – 韩川川 Jul 31 '15 at 13:06
  • I found that `filter` or `filterXPath` returns only the first occurence. So even if you have ul, and descendant children, it doesn't matter cause you will get only the first one, the parent. If you want to match only empty ul, you have to use `ul:empty` selector. – michail_w Jul 31 '15 at 18:59
  • filter:Filters the list of nodes with a CSS selector. – 韩川川 Aug 02 '15 at 11:18
  • 2
    Although the problem is not resolved, but still thank you ; maybe I should learn about XPath – 韩川川 Aug 02 '15 at 11:23
  • @michail_w I've found that filter returns all the occurrences. I've always just needed to loop through them. Ex. `$items_out = $crawler->filter('span.item_title'); $items_out->each(function ($node) { echo '
    ';
      print $node->text()."\n";
      echo '
    '; });`
    – Fireflight Feb 01 '16 at 00:19