2009-08-26 49 views
2

我正在使用SimpleHTMLDOM解析器來瀏覽一個網站,我想知道是否有任何錯誤處理方法。例如,如果鏈接中斷,則無法在代碼中前進並搜索文檔。簡單的HTML DOM解析器錯誤處理

謝謝。

回答

0

一個循環並繼續?

2
<?php 
$html = file_get_html('http://www.google.com/'); 

foreach($html->find('a') as $element) 
{ 
    if(empty($element->href)) 
    { 
    continue; //will skip <a> without href 
    } 

    echo $element->href . "<br>\n"; 
} 
?> 
相關問題