Search code examples
symfonydomcrawler

How to use wild card for domCrawler symfony?


Is it possible to use wild card to not select some UL LI element like following?

<ul>
<li id="i_touch1"></li>
<li id="i_touch2"></li>
<li id="i_touch3"></li>
<li></li> <-- this one
<li></li> <-- this one
</ul>

Best regards,


Solution

  • Something like this?

    $crawler->filterXPath('//ul/li[@id]');
    

    Explaination

    It select (at any deep level) all ul tags. Inside those tags, it search (and select) for li "direct childs" (so not nested ones) that has id attribute