我试图在 sitepoint javascript 论坛中删除每个主题的第一篇文章。但是 DOM 解析器会为我提供站点点 JAVASCRIPT 论坛中每个主题的所有帖子。也许我没有正确遍历 DOM ?下面是我的代码:
<?php
class Sitepoint extends Controller
{
public function index()
{
$this->load->helper('dom');
header('Content-Type: text/html; charset=utf-8');
echo '<ol>';
$html = file_get_html('http://www.sitepoint.com/forums/javascript-15');
foreach($html->find('a[id^="thread_title"]') as $topic) {
$post =$topic->href;
$posthtml = file_get_html($post);
$posthtml->find('div[id^="post_message"]', 0);
echo'<li>';
echo $topic->plaintext.'<br>';
echo $posthtml->plaintext.'<br>';
echo'</li>';
}
echo '</ol>';
}
}