简单的 html dom 不适用于表[类]


Simple html dom not working for a table[class]

我想使用网站的内容并将它们包含在我的"Simple 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;
?> 

警告: file_get_contents(http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN) [function.file-get-content]:无法打开流:HTTP 请求 失败!HTTP/1.1 500 内部服务器错误 public_html/elin-custom-code/simple_html_dom.php on 75路

致命错误:在 public_html/elin-custom-code/sklad-1.php 在第 9 行

作为参考链接:-

file_get_contents - 无法打开流:HTTP 请求失败!HTTP/1.1 404 未找到

大多数托管服务现在都阻止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() 返回"无法打开流:HTTP 请求失败!

祝你好运。

相关文章: