Conditions
In addition to their surrounding hierarchical structure, nodes can also be addressed based on conditions.
<?php
// Returns all ul nodes with an id attribute node $list = $xpath->query('//ul[@id]');
// Returns all li child nodes of the ul node with an id of "thelist"
$list = $xpath->query('//ul[@id = "thelist"]/li');
// Returns the first ul node that is a descendant of the context node $list = $xpath->query('//ul[1]');
// Returns the first li child node of each ul node
$list = $xpath->query('//ul/li[1]');
// Returns all ul nodes containing an li node with the value "foobar" $list = $xpath->query('//ul[li = "foobar"]');
?>
© DOM Extension — Web Scraping >>> Back to TABLE OF CONTENTS <<< | |
| Views: 434 | |
| Total comments: 0 | |