The title sums it up. I'm trying to query an HTML file for all div tags that contain the class result
and does not contain the class grid
.
<div class="result grid">skip this div</div>
<div class="result">grab this one</div>
Thanks!
The title sums it up. I'm trying to query an HTML file for all div tags that contain the class result
and does not contain the class grid
.
<div class="result grid">skip this div</div>
<div class="result">grab this one</div>
Thanks!
This should do it:
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile('test.html');
$xpath = new DOMXPath($doc);
$nodeList = $xpath->query(
"//div[contains(@class, 'result') and not(contains(@class, 'grid'))]");
foreach ($nodeList as $node) {
echo $node->nodeName . "\n";
}
//div[contains(concat(' ', normalize-space(@class), ' '), ' result ')]
, or //div[@class and contains(concat(' ', normalize-space(@class), ' '), ' result ')]
. –
Hillinck Your XPath would be //div[contains(concat(' ', @class, ' '), ' result ') and not(contains(concat(' ', @class, ' '), ' grid '))]
The XPATH syntax would be...
//div[not(contains(@class, 'grid'))]
© 2022 - 2024 — McMap. All rights reserved.