小编Mar*_*888的帖子

Goutte - dom 爬虫 - 删除节点

我的网站上有 html ( http://testsite.com/test.php ):

<div class="first">
  <div class="second">
     <a href="/test.php">click</a>
     <span>back</span>
  </div>
</div>
<div class="first">
  <div class="second">
     <a href="/test.php">click</a>
     <span>back</span>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想收到:

<div class="first">
  <div class="second">
     <a href="/test.php">click</a>
  </div>
</div>
<div class="first">
  <div class="second">
     <a href="/test.php">click</a>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

所以我想删除跨度。我在 Symfony2 中使用 Goutte 基于http://symfony.com/doc/current/components/dom_crawler.html

    $client = new Client();
    $crawler = $client->request('GET', 'http://testsite.com/test.php');

    $crawler->filter('.first .second')->each(function ($node) {
        //??????
    });
Run Code Online (Sandbox Code Playgroud)

php dom web-crawler symfony goutte

5
推荐指数
2
解决办法
4841
查看次数

标签 统计

dom ×1

goutte ×1

php ×1

symfony ×1

web-crawler ×1