[英]displaying div from webpage with simple_html_DOM
每当我回显内容时,我都尝试使用curl和simple_html_DOM从网页显示一些内容,它只是一个数组,如何获取它才能实际显示html内容?
<?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;
?>
谢谢
似乎内部<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>源,也发现了一个无服务器。
我不确定,但我认为您可能需要使用
$div->innertext;
获取div的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.