php 关于循环的问题!(采集网页内容)

WBOY
Release: 2016-06-23 13:47:59
Original
1196 people have browsed it

我在做论坛内容采集小程序,
本来是这样挑战网页采集的
if  ($_GET[id] $url="http://bbs.misranim.com/thread-".$_GET[id]."-1-1.html";

但是为了方便 我用了while循环 这样
$p=0;
while($p $url="http://bbs.misranim.com/thread-".$p."-1-1.html";
$p++;

问题就出现了,每次遇到被删除的空页面 他也会内容采集到数据库内
用if  ($_GET[id] 用了while 或者 for循环遇到被删除的空页面就出现这样的问题

图:遇到空页面就直接把上一页内容复制进去,比如 第13个帖子有内容,不过第14到17个帖子是被删除的空页面,它就会把13个帖子的内容加到这些里面去,后面也差不多!



用if  ($_GET[id] 13个帖子后面还几个都没有内容,所以直接跳过去,到第22个帖子 这样

我就想要这样的效果

用的是
 if (strlen($txt) > 5)//内容大与5个字符采集到数据库
{     
     $db->insert("INSERT INTO bbs_caiji (col_date,title,txt,url,type,source) VALUES ('".$col_date."','".$title1."','".$txt."','".$url."','BBS','misranim')");
}


为什么用while和for循环就出现这种问题呢?


回复讨论(解决方案)

打错字了,,第一行是跳转 不是挑战

应该不会出现你说的现象

代?不完整,只看提供的代?是?有??的。

每次循?後,都把$txt清?空??。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!