2011-06-04 173 views
1

喜 使用与simplehtmldom脚本代码(http://simplehtmldom.sourceforge.net/manual.htm): 我得到了一些错误吧:使用简单的HTML DOM

未能打开流: HTTP请求 失败!

我认为应该在这个脚本中使用curl而不是file_get_contents。 任何人都有一个想法如何inser卷曲在这个剧本?

+0

我们需要更多的信息。你有你的实际文件吗?有超过1个简单的HTML DOM脚本。 – Jem 2011-06-04 21:17:00

+0

警告:file_get_contents(http://example.com/new/id_123.html)无法打开流:HTTP请求失败!在/var/www/vhosts/domain/httpdocs/simple_html_dom.php在线40 其中第40行是$ dom-> load(call_user_func_array('file_get_contents',$ args),true); – goni 2011-06-04 21:48:44

+0

你可以从http://webarto.com/82/php-simple-html-dom-curl – 2011-07-13 12:50:45

回答

0
function get_data($url) 
{ 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); 
$data = curl_exec($ch); 
curl_close($ch); 
return $data; 
} 
$url = 'http://simplehtmldom.sourceforge.net/manual.htm'; 
echo $data = get_data($url); 
+0

oh thnx下载CURL的版本,但是如何将它与simplehtmldom整合? – goni 2011-06-04 21:55:34

+0

@goni以上都是php代码,为您提供数据作为字符串,尝试字符串函数,我们可以打破它。 – amolv 2011-06-04 22:01:03

0

我做这在我的CentOS

yum install php-mbstring 
yum install php-xml 
yum install php-xmlrpc 

每一件事情之后曾与simple_html_dom类

1

目前已经实现卷曲而不是file_get_contentsfound here一个simple_html_dom版本。

我在使用这个版本改变file_get_html功能 - >负载调用是这样的:

$dom->load(getWithCurl($args[0])); 

getWithCurl功能从get remote HTML with cURL and PHP拍摄。

它工作正常。