Find all elements except for those with certain class with simple_html_dom.php

StackOverflow https://stackoverflow.com/questions/22622733

  •  20-06-2023
  •  | 
  •  

Вопрос

I am using the simple_html_dom parser and I want to fetch data from html code that looks like this:

<pre class="root">
     <span class="B bgB"></span>
     <span class="B bgB"></span>
     <span class="B bgB"></span>
     <span class="B bgB"></span>
     <span class="W"></span>
     <span class="Y DH"> </span>
     <span class="Y DH">Some text</span>
</pre>

etc..

But I only want to get the content from the ones without the bgB class. So far I have this code:

$elements = $html->find('pre.root span[class!=bgB]');

But all spans are fetched and later printed, not only the ones without the bgB class. How can I accomplish this?

Это было полезно?

Решение

It can't be done with simple but if you switch to this one you can use the css :not pseudo:

$html = str_get_html($str);
$elements = $html->find('pre.root span:not(.bgB)');
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top