2013-05-03 81 views
1

嗨,我有簡單的HTML DOM代碼問題,它表明這個錯誤: -PHP - 未能打開流:沒有這樣的主機被稱爲

的file_get_contents(http://www.arakne-links.com) [function.file-GET-內容]:未能打開流: php_network_getaddresses:getaddrinfo失敗:沒有這樣的主機是已知的。 在d:\ XAMPP \ htdocs中\上線75

,因爲這個網址http://www.arakne-links.c現在沒有工作,我想

知道有什麼辦法可跳過網址這是不是報廢\ simple_html_dom.php工作..

這裏是我使用

ini_set('display_errors', 'on'); 
include_once('../../simple_html_dom.php'); 

// create HTML DOM 

$htmls = file_get_html('http://info.vilesilencer.com/top');  
foreach($htmls->find('a[rel="nofollow"]') as $e): 
$test = $e->href; 
$url = array($test); 
$html = array(); 
foreach($url as $key=>$value) { 

// get html plain-text for webpage & assign to html array. 

$html = file_get_html(trim($value)); 

// echo html plain text: 
echo $html->find('title', 0)->innertext; 

}  
endforeach; 

請幫我解決這個問題,它的代碼。

Thankyou

+0

您正在使用'file_get_content'函數的地方。 – 2013-05-03 11:57:00

+0

我的事情我修復它,並獲得在下一個網址,但現在有新的錯誤,我更換此代碼$ html = file_get_html(trim($ value)); // echo html純文本: echo $ html-> find('title',0) - > innertext;用$ html = @file_get_html(trim($ value)); if($ html){ echo $ html-> find('title',0) - > innertext; } else { //錯誤 \t echo'not working'; }但現在它顯示一些通知 – Corlax 2013-05-03 11:59:09

+0

你好MIss poo我在這裏使用file_get_content echo $ html-> find('title',0) - > innertext;它的一個simple_html_dom.php函數 – Corlax 2013-05-03 12:01:51

回答

4

如何在解析之前檢查URL?

ini_set('display_errors', 'on'); 
include_once('simple_html_dom.php'); 

function urlOk($url) { 
    $headers = @get_headers($url); 
    if($headers[0] == 'HTTP/1.1 200 OK') return true; 
    else return false; 
} 

// create HTML DOM 

$htmls = file_get_html('http://info.vilesilencer.com/top');  
foreach($htmls->find('a[rel="nofollow"]') as $e): 
    $test = $e->href; 
    $url = array($test); 
    $html = array(); 
    foreach($url as $key=>$value) { 
     // get html plain-text for webpage & assign to html array. 
     if (urlOk(trim($value))) { 
      $html = file_get_html(trim($value)); 
      echo $html->find('title', 0)->innertext; 
      echo "<br />"; 
     } else { 
     echo 'Error: URL '.$value.' doesn\'t exist.<br />'; 
     } 
}  
endforeach; 
?> 
+0

感謝這正是我正在尋找,但需要小幫助更多petra我得到這個錯誤注意:試圖獲取非對象的屬性在D:\ xampp \ htdocs \ scrap \ example \ scraping \ example_scraping_imdb.php在線22 .....它的標題標籤在第22行找不到。有沒有什麼辦法只有在標題標籤找到時才工作第22行 – Corlax 2013-05-03 12:46:07

+0

當沒有找到標題時,你需要'其他'部分嗎?否則,只需使用error_reporting(E_ALL^E_NOTICE)關閉通知; – Petra 2013-05-03 13:47:36

相關問題