【发布时间】:2016-07-19 19:09:55
【问题描述】:
我有这个代码
require_once 'vendor/autoload.php';
使用 Symfony\Component\DomCrawler\Crawler;
$html = <<<'HTML'
<!DOCTYPE html>
<html>
<body>
<p class="message">Hello World!
<span>This is span</span>
</p>
<p>Hello Crawler!
<span>This is span</span>
</p>
</body>
</html>
HTML;
$crawler = new Crawler($html);
foreach ($crawler->filter('body') as $domElement) {
$domElement->filter('span');
}
我收到此错误。
Fatal error: Call to undefined method DOMElement::filter()
我需要知道如何在 Foreach 循环中使用 CSS Selectors 选择元素?
我搜索了很多,但没有找到任何东西。
【问题讨论】: