0

コンテンツをエコーするたびにcurlとsimple_html_DOMを使用してWebページからコンテンツを表示しようとしていますが、これは単なる配列であり、実際に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;

?>

ありがとう

4

2 に答える 2

1

内側の<iframe>がクエリを台無しにしているようです。単純なhtmldomがそのように動作する理由がわかりません。クエリを次のように変更しないのはなぜですか。

$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>ソースを直接呼び出して、サーバーが見つかりませんでした。

于 2012-06-07T00:48:07.077 に答える
0

よくわかりませんが、使用する必要があるかもしれません

$div->innertext;

divのコンテンツを取得します。

于 2012-06-06T23:35:25.800 に答える