我想从网站上获取一些数据,每个网页都有自己的Feed。因此,我打算按顺序抓取所有这些Feed:
$maxPages = 5;
for ($i = 1; $i <= $maxPages; $i++)
{
// Create a new instance of the SimplePie object
$feed = new SimplePie();
$feed->set_feed_url('http://www.targetpage.org/forum?page=' . $i . '&foo=true');
$feed->enable_cache(false);
$feed->init();
foreach($feed->get_items() as $item)
{
$md5 = md5($item->get_id());
$title = $item->get_title();
$href = $item->get_link();
$content = $con->real_escape_string($item->get_content());
//Insert the gathered data into the database
$query = "INSERT INTO feed_items (md5, title, content, url) VALUES ('$md5', '$title', '$content', '$href')";
mysqli_query($con, $query);
}
}
因此,虽然每次通过'for'循环时URL都会改变,但SimplePie返回的内容是相同的。试图最终摧毁$feed
并没有帮助。我每次都能做些新鲜的食物?