Example HTML 5 for parsing:
<div id="orderDetails">
<div> ... any number of blocks with unnecessary stuff ... </div>
<div>Label for important info</div>
<table> ... some other block type ... </table>
<div>Some very important info here</div>
<div> ... any number of blocks with unnecessary stuff ... </div>
</div>
My PHP code looks like this:
$crawler = new \Symfony\Component\DomCrawler\Crawler($html);
$label = $crawler->filter('#orderDetails div:contains("Label for important info")');
$info = $label->parent()->next('div');
assert('Some very important info here' === $info->text(), 'Important info must be grabbed from HTML');
But unfortunately crawler has no methods parent
and next
. But.. it has parents
that gives me all parent nodes == all div's that i cannot differ.
So i have two questions in this case:
- How to get parent of current node? Not all nodes but "actual" one!
- How to traverse dom horizontally with some analogue of
next
/prev
?
Thanks.