新浪新闻小偷
新闻 新浪 小偷
2023-06-13 09:13:43 时间
新浪新闻小偷
1.
<html>
<head>
<metahttp-equiv="Refresh"content="60">
<METAHTTP-EQUIV="Pragma"CONTENT="no-cache">
<metahttp-equiv="Content-Type"content="text/html";charset="??????">
<title>新浪_新闻抓取程序</title>
</head>
<body>
<center><imgsrc="pic.gif"></center>
<?
$host="127.0.0.1";//MYSQL主机名
$namesql="????";//MYSQL用户名
$passsql="????";//MYSQL密码
$lib="news";//数据库名
$table="news";//数据库表名
$filename="http://news.sina.com.cn/news1000/index.shtml";//抓取的新闻页
$keytop="新闻开始";//新闻开始关键词
$keybottom="新闻结束";//新闻结束关键词
$conn=mysql_connect($host,$namesql,$passsql);
mysql_select_db($lib,$conn);
$fp=fopen($filename,"r",1);
$flag=0;$add="";$found=0;$end=0;$i=0;$temp[4]="";
while(!$end==1){
while(!$flag==1){
$word=fgetc($fp);
$add=$add.$word;
if($word=="<"andstrlen($add)==1){$flag=0;}
if($word=="<"andstrlen($add)!=1){$flag=1;$add=substr($add,0,strlen($add)-1);}
if($word==">"){$flag=1;}}
if(strchr($add,$keytop)){$found=1;}
if(strchr($add,$keybottom)){$found=0;$end=1;}
if(((strchr($add,"<")==Trueandstrchr($add,"href")==True)orstrchr($add,"<")==False)and$found==1){$text[$i]=$add;$i++;}
if($word=="<"and$flag==1){$add=$word;$flag=0;}else{$add="";$flag=0;}}
fclose($fp);
for($i=1;$i<sizeof($text)-1;$i+=5){
$temp[1]=$text[$i+1];$temp[2]=$text[$i+2];$temp[3]=$text[$i+3];$temp[4]=$text[$i+4];
$ins="select*from$tablewhereTITLE="$temp[3]"";
$list=mysql_query($ins,$conn);
@$count=mysql_num_rows($list);
if($count==0){
$ins="insertinto$table(TYPE,URL,TITLE,DATE)values("$temp[1]","$temp[2]","$temp[3]","$temp[4]")";
$list=mysql_query($ins,$conn);}}
mysql_close($conn);
?>
</body>
</html>
2.<?
$handle=fopen("http://news.sina.com.cn/news1000/","r");
$sign=0;
while(!feof($handle))
{
$message=fgets($handle,512);
if($sign==1)
{
print("$message");
}
if(ereg("新闻开始",$message,$result))
{
$sign=1;
}
elseif(ereg("新闻结束",$message,$result))
{
$sign=0;
}
}
fclose($handle);
?>
<html>
<head>
<metahttp-equiv="Refresh"content="60">
<METAHTTP-EQUIV="Pragma"CONTENT="no-cache">
<metahttp-equiv="Content-Type"content="text/html";charset="??????">
<title>新浪_新闻抓取程序</title>
</head>
<body>
<center><imgsrc="pic.gif"></center>
<?
$host="127.0.0.1";//MYSQL主机名
$namesql="????";//MYSQL用户名
$passsql="????";//MYSQL密码
$lib="news";//数据库名
$table="news";//数据库表名
$filename="http://news.sina.com.cn/news1000/index.shtml";//抓取的新闻页
$keytop="新闻开始";//新闻开始关键词
$keybottom="新闻结束";//新闻结束关键词
$conn=mysql_connect($host,$namesql,$passsql);
mysql_select_db($lib,$conn);
$fp=fopen($filename,"r",1);
$flag=0;$add="";$found=0;$end=0;$i=0;$temp[4]="";
while(!$end==1){
while(!$flag==1){
$word=fgetc($fp);
$add=$add.$word;
if($word=="<"andstrlen($add)==1){$flag=0;}
if($word=="<"andstrlen($add)!=1){$flag=1;$add=substr($add,0,strlen($add)-1);}
if($word==">"){$flag=1;}}
if(strchr($add,$keytop)){$found=1;}
if(strchr($add,$keybottom)){$found=0;$end=1;}
if(((strchr($add,"<")==Trueandstrchr($add,"href")==True)orstrchr($add,"<")==False)and$found==1){$text[$i]=$add;$i++;}
if($word=="<"and$flag==1){$add=$word;$flag=0;}else{$add="";$flag=0;}}
fclose($fp);
for($i=1;$i<sizeof($text)-1;$i+=5){
$temp[1]=$text[$i+1];$temp[2]=$text[$i+2];$temp[3]=$text[$i+3];$temp[4]=$text[$i+4];
$ins="select*from$tablewhereTITLE="$temp[3]"";
$list=mysql_query($ins,$conn);
@$count=mysql_num_rows($list);
if($count==0){
$ins="insertinto$table(TYPE,URL,TITLE,DATE)values("$temp[1]","$temp[2]","$temp[3]","$temp[4]")";
$list=mysql_query($ins,$conn);}}
mysql_close($conn);
?>
</body>
</html>
2.<?
$handle=fopen("http://news.sina.com.cn/news1000/","r");
$sign=0;
while(!feof($handle))
{
$message=fgets($handle,512);
if($sign==1)
{
print("$message");
}
if(ereg("新闻开始",$message,$result))
{
$sign=1;
}
elseif(ereg("新闻结束",$message,$result))
{
$sign=0;
}
}
fclose($handle);
?>
相关文章
- 【代码】利用Python每天自动发新闻到邮箱
- 定时抽取Oracle数据:实现自动化管理新闻(oracle定时抽取数据)
- 日经新闻:苹果 AirPods 3 无线耳机将于 8 月开始量产
- 每日开源新闻速递(2016/4/14):Ubuntu 16.04 将同时提供 snap 软件包格式
- 开源新闻速递:意大利国防部使用开源的 LibreOffice 节约了近三千万欧元支出
- 新闻速读 > Fanx 语言 3.2 发布,全面支持中文编程
- #新闻拍一拍# 国产兆芯飞腾 CPU、整机大促销:媲美 i5 的八核只需 1999 元
- #新闻拍一拍# GNOME 下一个版本将从 3.38 跳到 40.0
- Oracle中国发布最新新闻与进展(oracle中国最新动态)