我的网站上有 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)