当我试图从页面中获取一些不存在的内容时,我发现了这个错误:
The current node list is empty.
500 Internal Server Error - InvalidArgumentException
如何安全地检查此内容是否存在?下面是一些不起作用的例子:
if($crawler->filter('.PropertyBody')->eq(2)->text()){
// bla bla
}
if(!empty($crawler->filter('.PropertyBody')->eq(2)->text())){
// bla bla
}
if(($crawler->filter('.PropertyBody')->eq(2)->text()) != null){
// bla bla
}
谢谢,我帮自己做了:
$count = $crawler->filter('.PropertyBody')->count();
if($count > 2){
$marks = $crawler->filter('.PropertyBody')->eq(2)->text();
}
发布于 2012-08-07 21:21:32
你试过这样的东西吗?
$text = null;
if (!empty($body = $crawler->filter('.PropertyBody'))) {
if (!empty($node = $body->eq(2))) {
$text = $node->text();
}
}
$this->assertContains('yourText', $text);
发布于 2016-11-14 02:00:00
$marks = $crawler->filter('.PropertyBody')->count()
? $crawler->filter('.PropertyBody')->eq(2)->text()
: '';
发布于 2016-11-25 19:16:18
try {
$text = $crawler->filter('.PropertyBody')->eq(2)->text();
} catch (\InvalidArgumentException $e) {
// Handle the current node list is empty..
}
https://stackoverflow.com/questions/11846918
复制相似问题