【发布时间】:2015-07-31 11:47:00
【问题描述】:
根据特定的父节点获取子节点
function(Crawler $node,){
$node->filter('this>ul');
}
我怎样才能得到一个$node children,它不像CSS选择器#parent>child那样包含孙子?
【问题讨论】:
标签: php symfony web-crawler domcrawler
根据特定的父节点获取子节点
function(Crawler $node,){
$node->filter('this>ul');
}
我怎样才能得到一个$node children,它不像CSS选择器#parent>child那样包含孙子?
【问题讨论】:
标签: php symfony web-crawler domcrawler
this 或 parent 选择器。$node->filter('>ul');
【讨论】:
filter 或filterXPath 只返回第一次出现。因此,即使您有 ul 和后代子代,也没关系,因为您只会得到第一个,即父代。如果你只想匹配空的ul,你必须使用ul:empty选择器。
$items_out = $crawler->filter('span.item_title'); $items_out->each(function ($node) { echo '<pre>'; print $node->text()."\n"; echo '</pre>'; });