php - domxpath - Extract li tags from second ul -


i trying extract second ul's li tags following. unfortunately, there no classes or ids in html help

<ul>     <li>some text</li>     <li>some text</li>     <li>some text</li> </ul>  <ul>     <li>some more text</li>     <li>some more text</li>     <li>some more text</li> </ul> 

i have tried (a few things, actually):

    $ul = $xpath->query('//ul')->item(1);     $query = '/li';     $lis = $xpath->evaluate($query, $ul); 

thinking me second ul, , can extract there. me second ul's html, i'm misunderstanding `->evaluate? because li's li's, not second ul.

you can directly access them using xpath:

$xpath->query('//ul[2]/li'); 

example:

$html = <<<eof <ul>     <li>some text</li>     <li>some text</li>     <li>some text</li> </ul>  <ul>     <li>some more text</li>     <li>some more text</li>     <li>some more text</li> </ul> eof;  $doc = new domdocument(); $doc->loadhtml($html);  $selector = new domxpath($doc);  // iterate through them... foreach($selector->query('//ul[2]/li') $li) {     echo $li->nodevalue . php_eol; } 

~


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -