【问题标题】:displaying div from webpage with simple_html_DOM使用 simple_html_DOM 从网页显示 div
【发布时间】:2012-06-06 23:28:06
【问题描述】:

我正在尝试使用 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;

?>

谢谢

【问题讨论】:

    标签: php curl simple-html-dom


    【解决方案1】:

    似乎 inner 搞乱了查询。 我不知道为什么简单的 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 内部进行的调用使用的是我的 url,而不是我从中获取信息的站点,所以我得到的只是页面不能在服务器消息中找到
    • 有没有办法在我回显变量之前更改属性,例如更改 iframe 上的 src?
    【解决方案2】:

    我不确定,但我认为您可能必须使用

    $div->innertext;
    

    获取div的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 2018-12-11
      相关资源
      最近更新 更多