Symfony 2 Dom Crawler:如何在Element中只获取text()

使用Dom Crawler只获取文本(没有标记).
$html = EOT<<<
  <div class="coucu">
    Get Description <span>Coucu</span>
  </div>
EOT;

$crawler = new Crawler($html);
$crawler = $crawler->filter('.coucu')->first()->text();

输出获取描述Coucu

我想输出(仅):获取描述

更新:

我找到了一个解决方案:(但这是非常糟糕的解决方案)

...
$html = $crawler->filter('.coucu')->html();
// use strip_tags_content in https://PHP.net/strip_tags
$html = strip_tags_content($html,'span');

解决方法

陷入同样的​​境地.我结束了:
$html = $crawler->filter('.coucu')->html();
$html = explode("<span",$html);
echo trim($html[0]);

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些