采集入库程序原理
2014-06-19 23:52
183 查看
php开发通用采集程序(一)
php采集程序构建基本步骤:
采集程序是什么?获取远程数据(文字、图片、图片)并快速保存到本地或指定地址。
如天气预报(小偷程序):
远程获取--》替换内容--》展示给用户
如实时更新的新闻(采集内容):
远程获取--》提取内容--》分类存储--》读取内容---》展示内容
*************************
设计PHP采集入库UML
列表正则:
终端正则:
**************************
file_get_contents()获取远程页面内容
preg_match_all()匹配列表
preg_match()匹配终端
preg_replace() :过滤终端
**************************
新建一个列表文件:lb.php
echo $con=file_get_cotents($_GET
preg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
新建vi。php获取标题
vi.php
$con=file_get_contents();
$preg="<title>(.*)</title>/iUs";//大小写不敏感,防止贪婪匹配,防止换行
echo zz($preg,$con);
function zz($preg,$con,$num=1){
preg_match($preg,$con,$arr);
return $arr[$num];
}
echo $arr[1];//获取标题
echo "<a href=vi.php?url=".$v.">".arr[2][$id]."<br>";
======================================
php100:83:采集程序
lb.php
<?php
if($_GET[id]){
$con=file_get_cotents($_GET[url].$_GET[id]."shtml");
$preg ="/<h1><a href='(.*)' target='_blank'>(.*)</a><span>/iUs";
perg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
$_GET[id]++;
echo "<script>location.href='lb.php?id='.$_GET[id]."</script>";
}
?>
http://www.xinhuanet.com/finance/tzxx.htm
===============================================================
操作步骤:
1.新建一个数据库caiji,tep_url表,id,title,content,11 ,100,150
2.新建一个conn.php,插入的语句可以通过phpmyadmin插入一个语句简单的获得
3.新建一个vi.php
4.单条入库获取下一条。
临时的路径列表:
完善我的入库表。
假设删删除了其中的一条Id值,怎么办?删除了第9条!
多加一条语句
$sql2="select * from tmp_url where id>'$gid'order by id asc limit 1
code:
ls.php
<?php
include_once('conn.php');
if(@$_GET['id']<=6 && @$_GET['id']){
if(@$_GET['id']==1){
$con=file_get_contents("http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/" target=_blank>);
$preg ="#<h1><a href='(.*)' target='_blank'>(.*)</a><span>#iUs";
preg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
新建vi。php获取标题
vi.php
$con=file_get_contents();
$preg="<title>(.*)</title>/iUs";//大小写不敏感,防止贪婪匹配,防止换行
echo zz($preg,$con);
function zz($preg,$con,$num=1){
preg_match($preg,$con,$arr);
return $arr[$num];
}
echo $arr[1];//获取标题
echo "<a href=vi.php?url=".$v.">".arr[2][$id]."<br>";
======================================
php100:83:采集程序
lb.php
<?php
if($_GET[id]){
$con=file_get_cotents($_GET[url].$_GET[id]."shtml");
$preg ="/<h1><a href='(.*)' target='_blank'>(.*)</a><span>/iUs";
perg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
$_GET[id]++;
echo "<script>location.href='lb.php?id='.$_GET[id]."</script>";
}
?>
http://www.xinhuanet.com/finance/tzxx.htm
===============================================================
操作步骤:
1.新建一个数据库caiji,tep_url表,id,title,content,11 ,100,150
2.新建一个conn.php,插入的语句可以通过phpmyadmin插入一个语句简单的获得
3.新建一个vi.php
4.单条入库获取下一条。
临时的路径列表:
完善我的入库表。
假设删删除了其中的一条Id值,怎么办?删除了第9条!
多加一条语句
$sql2="select * from tmp_url where id>'$gid'order by id asc limit 1
code:
ls.php
<?php
include_once('conn.php');
if(@$_GET['id']<=6 && @$_GET['id']){
if(@$_GET['id']==1){
$con=file_get_contents("[url=http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/]http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/");
}else{
$con=file_get_contents("[url=http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/%22.@$_GET['id'].%22.html]http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/".@$_GET['id'].".html");
}
$preg="#<td height=\"25\"><img src=\"(.*)\"> <a href=\"(.*)\" style=\"font-size:14px\"><strong><b>(.*)</b></strong></a></td>#iUs";
preg_match_all($preg,$con,$arr);
foreach ($arr[2] as $id=>$v){
echo "<a href=vi.php?url=".$v.">".$arr[3][$id]."</a><br>";
$sql="INSERT INTO `caiji` (`id`, `title`, `url`) VALUES (NULL, '".$arr[3][$id]."', '".$v."')";
mysql_query($sql);
}
@$_GET['id']++;
echo "正在采集列表....".@$_GET['id'];
echo "<script>location.href='ls.php?id="."'%3C/script].@$_GET['id']."'</script>";
}else{
echo "采集结束";
}
?>
vi.php
<?php
include_once('conn.php');
$gid=(int)@$_GET['id'];
$sql="select * from `caiji` where `id`='$gid'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$con=file_get_contents($row['url']);
echo $title=zz("#<title>(.*)</title>#iUs",$con);
echo $con=zz("#<ul class=\"downurllist\">(.*)</ul>#iUs",$con);
$content=addslashes($con);
$intosql="INSERT INTO `caiji`.`news` (`id`, `title`, `content`) VALUES (NULL,'$title','$content')";
mysql_query($intosql);
$sql2="select * from `caiji` where `id`>'$gid' order by `id` asc limit 1";
$query2=mysql_query($sql2);
$row2=mysql_fetch_array($query2);
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];
}
?>
php采集程序构建基本步骤:
采集程序是什么?获取远程数据(文字、图片、图片)并快速保存到本地或指定地址。
如天气预报(小偷程序):
远程获取--》替换内容--》展示给用户
如实时更新的新闻(采集内容):
远程获取--》提取内容--》分类存储--》读取内容---》展示内容
*************************
设计PHP采集入库UML
列表正则:
终端正则:
**************************
file_get_contents()获取远程页面内容
preg_match_all()匹配列表
preg_match()匹配终端
preg_replace() :过滤终端
**************************
新建一个列表文件:lb.php
echo $con=file_get_cotents($_GET
preg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
新建vi。php获取标题
vi.php
$con=file_get_contents();
$preg="<title>(.*)</title>/iUs";//大小写不敏感,防止贪婪匹配,防止换行
echo zz($preg,$con);
function zz($preg,$con,$num=1){
preg_match($preg,$con,$arr);
return $arr[$num];
}
echo $arr[1];//获取标题
echo "<a href=vi.php?url=".$v.">".arr[2][$id]."<br>";
======================================
php100:83:采集程序
lb.php
<?php
if($_GET[id]){
$con=file_get_cotents($_GET[url].$_GET[id]."shtml");
$preg ="/<h1><a href='(.*)' target='_blank'>(.*)</a><span>/iUs";
perg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
$_GET[id]++;
echo "<script>location.href='lb.php?id='.$_GET[id]."</script>";
}
?>
http://www.xinhuanet.com/finance/tzxx.htm
===============================================================
操作步骤:
1.新建一个数据库caiji,tep_url表,id,title,content,11 ,100,150
2.新建一个conn.php,插入的语句可以通过phpmyadmin插入一个语句简单的获得
3.新建一个vi.php
4.单条入库获取下一条。
临时的路径列表:
完善我的入库表。
假设删删除了其中的一条Id值,怎么办?删除了第9条!
多加一条语句
$sql2="select * from tmp_url where id>'$gid'order by id asc limit 1
code:
ls.php
<?php
include_once('conn.php');
if(@$_GET['id']<=6 && @$_GET['id']){
if(@$_GET['id']==1){
$con=file_get_contents("http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/" target=_blank>);
$preg ="#<h1><a href='(.*)' target='_blank'>(.*)</a><span>#iUs";
preg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
新建vi。php获取标题
vi.php
$con=file_get_contents();
$preg="<title>(.*)</title>/iUs";//大小写不敏感,防止贪婪匹配,防止换行
echo zz($preg,$con);
function zz($preg,$con,$num=1){
preg_match($preg,$con,$arr);
return $arr[$num];
}
echo $arr[1];//获取标题
echo "<a href=vi.php?url=".$v.">".arr[2][$id]."<br>";
======================================
php100:83:采集程序
lb.php
<?php
if($_GET[id]){
$con=file_get_cotents($_GET[url].$_GET[id]."shtml");
$preg ="/<h1><a href='(.*)' target='_blank'>(.*)</a><span>/iUs";
perg_match_all($preg,$conn,$arr);
foreach($arr[1] as $id=>$v){
echo $v." "arr[2][$id]."<br>";
}
$_GET[id]++;
echo "<script>location.href='lb.php?id='.$_GET[id]."</script>";
}
?>
http://www.xinhuanet.com/finance/tzxx.htm
===============================================================
操作步骤:
1.新建一个数据库caiji,tep_url表,id,title,content,11 ,100,150
2.新建一个conn.php,插入的语句可以通过phpmyadmin插入一个语句简单的获得
3.新建一个vi.php
4.单条入库获取下一条。
临时的路径列表:
完善我的入库表。
假设删删除了其中的一条Id值,怎么办?删除了第9条!
多加一条语句
$sql2="select * from tmp_url where id>'$gid'order by id asc limit 1
code:
ls.php
<?php
include_once('conn.php');
if(@$_GET['id']<=6 && @$_GET['id']){
if(@$_GET['id']==1){
$con=file_get_contents("[url=http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/]http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/");
}else{
$con=file_get_contents("[url=http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/%22.@$_GET['id'].%22.html]http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/".@$_GET['id'].".html");
}
$preg="#<td height=\"25\"><img src=\"(.*)\"> <a href=\"(.*)\" style=\"font-size:14px\"><strong><b>(.*)</b></strong></a></td>#iUs";
preg_match_all($preg,$con,$arr);
foreach ($arr[2] as $id=>$v){
echo "<a href=vi.php?url=".$v.">".$arr[3][$id]."</a><br>";
$sql="INSERT INTO `caiji` (`id`, `title`, `url`) VALUES (NULL, '".$arr[3][$id]."', '".$v."')";
mysql_query($sql);
}
@$_GET['id']++;
echo "正在采集列表....".@$_GET['id'];
echo "<script>location.href='ls.php?id="."'%3C/script].@$_GET['id']."'</script>";
}else{
echo "采集结束";
}
?>
vi.php
<?php
include_once('conn.php');
$gid=(int)@$_GET['id'];
$sql="select * from `caiji` where `id`='$gid'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$con=file_get_contents($row['url']);
echo $title=zz("#<title>(.*)</title>#iUs",$con);
echo $con=zz("#<ul class=\"downurllist\">(.*)</ul>#iUs",$con);
$content=addslashes($con);
$intosql="INSERT INTO `caiji`.`news` (`id`, `title`, `content`) VALUES (NULL,'$title','$content')";
mysql_query($intosql);
$sql2="select * from `caiji` where `id`>'$gid' order by `id` asc limit 1";
$query2=mysql_query($sql2);
$row2=mysql_fetch_array($query2);
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];
}
?>
相关文章推荐
- 浅谈自动采集程序及入库
- 浅谈自动采集程序及入库
- [轉]ASP采集-ASP采集程序原理
- 浅谈自动采集程序及入库
- PHP 采集程序原理分析篇
- 浅谈自动采集程序及入库
- PHP采集程序原理分析
- ASP网站数据采集程序制作:一个采集入库生成本地文件的几个FUCTION(可用来生成HTML静态网页)
- ASP采集-ASP采集程序原理
- 浅谈自动采集程序及入库
- ASP下实现自动采集程序及入库的代码
- 小偷程序和采集入库
- 自动采集程序及入库教程
- ASP采集-ASP采集程序原理
- ASP网站数据采集程序制作:一个采集入库生成本地文件的几个FUCTION(可用来生成HTML静态网页)
- 浅谈自动采集程序及入库
- 天气小偷程序,自动采集信息入库
- 浅谈ASP程序实现自动采集程序及入库
- asp 小偷采集程序原理与常用函数方法
- PHP开发通用采集入库程序