一:数据库
-- 数据库: `caiji`
--
-- --------------------------------------------------------
--
-- 表的结构 `news`
--
CREATE TABLE `news` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(50) collate gb2312_bin NOT NULL,
`content` text collate gb2312_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312 COLLATE=gb2312_bin AUTO_INCREMENT=58 ;
-- --------------------------------------------------------
--
-- 表的结构 `tmp_url`
--
CREATE TABLE `tmp_url` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL,
`url` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=166 ;
二:连接数据库文件conn.php
/*
author: www.php100.com 视频教程源码 84讲
*/
mysql_connect("localhost","root","hongwei");
mysql_select_db("caiji");
mysql_query("set names 'GBK'");
?>
三:列表文件ls.php
/*
author: www.php100.com 视频教程源码 84讲
*/
include_once("conn.php");
if($_GET[id]<=60 && $_GET[id]){
$con=file_get_contents(".$_GET[id].".shtml");
$preg = "#
·
(.*)#iUs";preg_match_all($preg,$con,$arr);
foreach($arr[1] as $id=>$v){
$sql="INSERT INTO `tmp_url` (`id`, `title`, `url`) VALUES (NULL, '".$arr[2][$id]."', '".$v."');";
mysql_query($sql);
}
$_GET[id]++;
echo "正在采集列表....".$_GET[id];
echo "<script>location.href='ls.php?id=".$_GET[id]."'</script>";
}else{
echo "采集结束";
}
?>
四:展示页面文件vi.php
/*
author: www.php100.com 视频教程源码 84讲
*/
include_once("conn.php");
$gid =(int)$_GET[id];
$sql="select * from tmp_url where id='$gid'";
$q=mysql_query($sql);
$row = mysql_fetch_array($q);
$con=file_get_contents($row[url]);
echo $titles="".zz("#
echo $conts=zz("#
(.*)
#iUs",$con);
$intosql="INSERT INTO `news` (`id`, `title`, `content`) VALUES (NULL, '$titles', '$conts');";
mysql_query($intosql);
//============================
$sql2="select * from tmp_url where id>'$gid' order by id asc limit 1";
$q2=mysql_query($sql2);
$row2 = mysql_fetch_array($q2);
echo $row2[0].$row2[1]."
";
if($row2[0]){
echo "<script>location.href='vi.php?id=".$row2[0]."'</script>";
}
function zz($preg,$con,$num=1){
preg_match($preg,$con,$arr);
return $arr[$num];
}
?>