2012-06-06 43 views
0

我想显示一些内容从网页使用卷曲和simple_html_DOM每当我回声内容它只是一个数组如何让它实际显示HTML内容?从网页显示div与simple_html_DOM

<?php 
echo ("hello"); 

include 'simple_html_dom.php'; 

$curl = curl_init(); 
curl_setopt ($curl, CURLOPT_URL, "http://catalog.hastingsfilter.com/startautoapps.html"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($curl, CURLOPT_REFERER, "http://catalog.hastingsfilter.com/startautoapps.html"); 

$result = curl_exec ($curl); 
curl_close ($curl); 
//write contents of $result to file 
$File = "page.txt"; 
$fh = fopen($File, 'w') or die("can't open file"); 
fwrite($fh, $result); 
fclose($fh); 
//turn file into dom object 
$page = file_get_html("page.txt"); 
$div = $page->find('div[id=columnright]'); 
echo $div; 

?> 

感谢

回答

1

似乎内部< iframe>正在搞乱查询。 林不知道为什么简单的HTML DOM的行为那样.. 为什么不更改查询到:

$div = $page->find("iframe[name='main2']"); 
echo $div[0]->innertext; 

编辑:

你可以改变的.src属性是这样的:

$page = file_get_html("page.txt"); 
... 
$page->find("iframe[name='main2']",0)->src = "foo"; 
$thehtml = $page->save(); 

顺便说一句,我直接打电话给< iframe>源,也得到了 一个没有发现服务器..

+0

好吧我得到它使用outertext显示...但它在iframe内部调用是使用我的网址,而不是我即时获取信息的网站所以我得到的是页面无法在服务器消息中找到 – arrowill12

+0

有没有办法在我回显变量之前更改属性,例如更改iframe上的src? – arrowill12

+0

检查编辑后 – 2012-06-07 01:30:11

0

我不知道,但我想你可能需要使用

$div->innertext; 

得到div的内容。

+0

nope没有工作它使字数组消失,虽然 – arrowill12