简单 html dom 不适用于 table[class]
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;
?>
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
作为link供参考:-
大多数主机提供现在阻止 furl_open
参数,允许您使用 file_get_contents()
从外部加载数据 url.
您可以使用 CURL
或 PHP
客户端库,例如 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
因此,出于安全原因,这些方法调用(CURL
和 file_get_contents
)似乎在该站点上被阻止了。
您也可以试试这个 link 答案,也许您会得到一些有用的输出:-
祝你好运。
我想使用一个网站的内容,并通过 "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;
?>
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
作为link供参考:-
大多数主机提供现在阻止 furl_open
参数,允许您使用 file_get_contents()
从外部加载数据 url.
您可以使用 CURL
或 PHP
客户端库,例如 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
因此,出于安全原因,这些方法调用(CURL
和 file_get_contents
)似乎在该站点上被阻止了。
您也可以试试这个 link 答案,也许您会得到一些有用的输出:-
祝你好运。