需要使用php进行DOM遍历的帮助吗
我试着用下面的代码删除这个论坛的内容帖子需要使用php进行DOM遍历的帮助吗,php,dom,simple-html-dom,Php,Dom,Simple Html Dom,我试着用下面的代码删除这个论坛的内容帖子 $rows = $html->find('.post_table'); $array = array(); foreach($rows as $go){ $post_text = $go->find('.post_td_right > .post_text')->innertext; $array[]= array( 'content'=> $post_text ); } echo
$rows = $html->find('.post_table');
$array = array();
foreach($rows as $go){
$post_text = $go->find('.post_td_right > .post_text')->innertext;
$array[]= array(
'content'=> $post_text
);
}
echo json_encode($array);
我使用var_dump($rows),它是一个对象,我真的不知道为什么会出错。需要你的帮助 论坛通常有一个RSS提要来帮助满足这类需求。事实证明,您正在清理的站点为您提供了以下信息: 我们现在可以使用XML解析器而不是DOM刮刀,这将更加高效。比如,
<?php
$rss = file_get_contents('http://rss.forum.lowyat.net/topic/3424996'); //Or use cURL
$xml = simplexml_load_string($rss);
$array = array();
foreach($xml->channel->item as $posts) {
$post = (array) $posts->description;
$array[] = htmlentities($post[0]);
}
echo "<pre>";
echo print_r($array);
echo "</pre>";
channel->item as$posts){
$post=(数组)$posts->description;
$array[]=htmlentities($post[0]);
}
回声“;
回波打印(阵列);
回声“;
为什么$rows
作为对象是错误的?$html
是什么类的对象?你有权限删除内容吗?通常论坛有一个你可以使用的RSS提要,这更简单,你不需要获得许可就可以从他们的网站上抓取。事实证明确实如此:rss不是实时的