2

Here is the html snippet from where I want to extract all the link elements with commas but not the span elements inside the span class tl

<span class="tl"><a href="/en/laravel/" class="c">laravel</a>, <span>goutte</span>, <a href="/en/php/">php</a>, <span>dom crawler</span>, <span>guzzle</span>, <span>web scrapper</span> </span>  

I tried doing this

$links['tag'] = $crawler->filter('span.tl >:not(span)')->each(function ($node) {
       return $node->text();
         });

but it doesn't work. Can anyone please help me to extract the code?

on a var_dump of $links i am getting

array (size=1) 
'tag' => array (size=2) 
0 => string 'laravel' (length=7) 
1 => string 'php' (length=3) 

I am expecting something like this

array (size=1) 
'tag' => array (size=1)
0 => string 'laravel, php' (length=12) 

where ',' also present as text() method should return them too.

FYI if i use this code

     $links['tag'] = $crawler->filter('span.tl')->each(function ($node) {
  return $node->text();

I am getting this output

 array (size=1) 
    'tag' => array (size=1)
    0 => string 'laravel, goutte, php, dom crawler, guzzle, web scrapper' (length=55) 

I want to select all the tags with links only.

coolsaint
  • 1,291
  • 2
  • 16
  • 27

0 Answers0