2016-02-28 35 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

感谢您的评分。如果不投票,那么也是投票。 –