Php Symfony爬虫从foreach中的getted childs获取子节点?
我和你一起工作 XML看起来像:Php Symfony爬虫从foreach中的getted childs获取子节点?,php,xml,symfony,parsing,web-crawler,Php,Xml,Symfony,Parsing,Web Crawler,我和你一起工作 XML看起来像: <Tours> <Tour id="1"> <Termins> <Termin> ... 但我想找到这样的方法来使用爬虫程序:(主要的一点是没有来自“top”的选择器,但来自元素witch,它已经在foreach中了) 此时,当您通过爬虫时,您将得到一个DOMNode数组。然后可以为该子文档创建新的爬网程序 foreach
<Tours>
<Tour id="1">
<Termins>
<Termin>
...
但我想找到这样的方法来使用爬虫程序:(主要的一点是没有来自“top”的选择器,但来自元素witch,它已经在foreach中了)
此时,当您通过爬虫
时,您将得到一个DOMNode
数组。然后可以为该子文档创建新的爬网程序
foreach ($crawler->filter('tour') as $tour) {
$tourCrawler = new Crawler($tour);
$tourCrawler->attr('id'); // 1...
foreach ($tourCrawler->filter('termin') as $termin) {
// Access nodes or create further crawlers
}
}
foreach ($crawler->children() as $tour) {
foreach($tour->first('Termins')->children() as $termin)
foreach ($crawler->filter('tour') as $tour) {
$tourCrawler = new Crawler($tour);
$tourCrawler->attr('id'); // 1...
foreach ($tourCrawler->filter('termin') as $termin) {
// Access nodes or create further crawlers
}
}