2012-04-02 20 views
0

我想解析http://gmmobile.atm-mi.it/wsbw/InfoTraffico/頁面,該頁面不需要認證。然而,當我試圖通過PHP腳本訪問它,以分析其內容,我收到一個錯誤:從php腳本訪問頁面時發生有趣的500錯誤

Warning: file_get_contents(http://gmmobile.atm-mi.it/wsbw/InfoTraffico/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /iPhone/simplehtmldom_1_5/simple_html_dom.php on line 70

我使用的代碼如下:

include('simple_html_dom.php'); 
// Create DOM from URL or file 
$url='http://gmmobile.atm-mi.it/wsbw/InfoTraffico/'; 
echo $url; 
$html = file_get_html($url); 
echo $html; 
$i=0; 
foreach($html->find('option') as $content) 
{ 
    $linea=$content->value; 
    $destination=$content->title; 
     $i++; 

} 

可能是什麼這個問題以及我如何解決它?

回答

0

嘗試添加的User-Agent:

$url = 'http://gmmobile.atm-mi.it/wsbw/InfoTraffico/'; 
$options = array('http' => array('header' => "User-Agent: myFooAgent\r\n")); 
$context = stream_context_create($options); 
echo file_get_contents($url, false, $context); 
+0

謝謝,我會看看的建議。 – 2012-04-03 08:22:17

+0

非常感謝和抱歉沒有及時執行它,但我不得不解決其他問題,並發現我想實現的應用程序已經完成。 – 2012-04-17 15:37:08

+0

你應該關閉這個問題。 – 2012-04-17 16:05:14

相關問題