How can I safely check is node empty or not? (Symfony 2 Crawler)

前端 未结 3 776
-上瘾入骨i
-上瘾入骨i 2021-02-05 03:53

When I try to take some nonexistent content from page I catch this error:

The current node list is empty.
500 Internal Server Error - InvalidArgumentException 
<         


        
3条回答
  •  没有蜡笔的小新
    2021-02-05 04:57

    try {
        $text = $crawler->filter('.PropertyBody')->eq(2)->text();
    } catch (\InvalidArgumentException $e) {
        // Handle the current node list is empty..
    }
    

提交回复
热议问题