【发布时间】:2014-03-17 00:37:42
【问题描述】:
我正在使用 PHP-Spider 抓取网站,但是当它找不到 .class 时会抛出错误: InvalidArgumentException:当前节点列表为空。
代码是这样的:
foreach ($spider->getPersistenceHandler() as $resource) {
echo $resource->getCrawler()->filterXpath('//title')->text().", ";
echo $resource->getCrawler()->filterXpath("//meta[@name='description']/@content")->text()."<br>";
echo $resource->getCrawler()->filterXpath("//div[@class='buyFooter']")->text();
echo $resource->getCrawler()->filterXpath("//div[@class='listFooter']")->text();
}
在某些页面上存在 .buyFooter 类,而在其他页面上存在 .listFooter 类。
有没有办法检查它是否存在?
我试过 isset & !empty 但没有运气
【问题讨论】:
-
你试过
->count()吗?在这里查看 [stackoverflow.com/questions/11846918/… [1]:stackoverflow.com/questions/11846918/…
标签: php symfony web-crawler