2016-02-28 32 views
1

我想用一個網站的內容,包括它們與"Simple Html DOM"礦,可惜這通常適用於另一個網站的代碼,無法在這種特殊情況下:簡單的HTML DOM不工作的表[類]

<?php 

// Note you must download the php files from the link above 
// and link to them on this line below. 
include_once('simple_html_dom.php'); 


$html = file_get_html('http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN'); 
$elem = $html->find('table[class=Descrizione]', 0); 
echo $elem; 

?> 

Warning: file_get_contents(http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in public_html/elin-custom-code/simple_html_dom.php on line 75

Fatal error: Call to a member function find() on a non-object in public_html/elin-custom-code/sklad-1.php on line 9

+0

它看起來像頁面需要用戶代理或其他東西。它投擲500意味着有錯誤。你的'致命錯誤'是因爲'$ html'是錯誤的。 – chris85

回答

2

爲紐帶的參考: -

file_get_contents - failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

大多數託管提供了現在阻止furl_open參數,它允許您使用file_get_contents()從外部URL加載數據。

您可以使用CURLPHP客戶端庫,如Guzzle

要確保我只是用CURL檢查什麼是用下面的代碼的幫助下確切的問題: -

<?php 
$curl_handle=curl_init(); 
curl_setopt($curl_handle, CURLOPT_URL,'http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN'); 
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); 
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name'); 
$query = curl_exec($curl_handle); 
curl_close($curl_handle); 
echo "<pre/>";print_r($query); 
?> 

輸出: - http://prntscr.com/a91nl5

如此看來,出於安全原因,這些方法調用(CURLfile_get_contents)在該站點上被阻止。

你可以試試這個鏈接回答還,可能你會得到一些有用的輸出: -

PHP file_get_contents() returns "failed to open stream: HTTP request failed!"

好運。

+0

謝謝你的回答! 如果我正確地理解了你,由於安全原因,這是不可能的? –

+0

看起來,這就是爲什麼我給了你兩個鏈接以及我的努力。還有更多的答案,你需要檢查並嘗試它們。也許你可以得到一些有用的東西。對我來說,看起來安全是你的問題。 –

+0

感謝您的評分。如果不投票,那麼也是投票。 –