back
back
我想收到:
$client = new Client();
$crawler = $client->request('GET', 'http://testsite.com/test.php');
$crawler->filter('.first .second')->each(function ($node) {
//??????
});
解决方法:
The DomCrawler component eases DOM navigation for HTML and XML documents.
并且:
While possible, the DomCrawler component is not designed for manipulation of the DOM or re-dumping HTML/XML.
DomCrawler旨在从DOM文档中提取细节而不是修改它们.
然而…
由于PHP通过引用传递对象,而Crawler基本上是DOMNodes的包装器,因此在技术上可以修改底层DOM文档:
// will remove all span nodes inside .second nodes
$crawler->filter('html .content h2')->each(function (Crawler $crawler) {
foreach ($crawler as $node) {
$node->parentNode->removeChild($node);
}
});
标签:php,dom,web-crawler,symfony,goutte
来源: https://codeday.me/bug/20190628/1319962.html