+ -
当前位置:首页 → 问答吧 → 一个抓取瑞星每周病毒情况代码

一个抓取瑞星每周病毒情况代码

时间:2007-07-23

来源:互联网

<?php
/*
获取瑞星的每周每周病毒信息
修改$j 为页数-1
*/
set_time_limit(0);
$j=9;
$link =mysql_connect("localhost","root","");
mysql_select_db("oa");
function getpage($url) {  //分析病毒周报形如 http://it.rising.com.cn/Channels ... 4899856d43378.shtml 页面函数
        $code1 = file_get_contents($url,"r");
        preg_match_all("/(<br \/>)([\s\S]*)(<h3>相关文章)/",$code1,$out);  
        return         str_replace("<h3>相关文章","",$out[0][0]);
}
function insert_to_db($page){//分析所有链接页面的函数如:http://it.rising.com.cn/Channels ... us_Week/index.shtml并写入数据库
        global  $link;
$fistpage_code =file_get_contents($page,"r");
preg_match_all("/(<ul>)([\s\S]+)(<\/ul>)/",$fistpage_code,$out);  //将<ul></ul>之间代码提出
$fistpage_code_1 =$out[0][0];
preg_match_all("/(\/)(.*)(\.)(shtml)|(html)|(htm)/",$fistpage_code_1,$out1); //提取所有病毒周报的链接

foreach($out1[0] as $str){
        $url[]="http://it.rising.com.cn".$str;  //构建回完整的链接
}
preg_match_all("/(\">)(.*)(<\/a>)/",$fistpage_code_1,$out2);  //提取所有病毒周报的标题
foreach ($out2[0] as $str) {
        $text[]=str_replace("\">","",str_replace("</a>","",$str));
}
preg_match_all("/<span>.*<\/span>/",$fistpage_code_1,$out3); // 提取发布的日期
foreach ($out3[0] as $str) {
        $date[]=str_replace("<span>","",str_replace("</span>","",$str));
}

if(count($url)==count($date) and count($url)==count($text)){
        for($i =count($date)-1;$i>-1;$i--){
                $content =getpage($url[$i]);
                $fbrq =date("Y-m-d",mktime());
                $sql ="insert into AntiVirus (url,url_text,url_date,url_content,fbrq)";
                $sql .=" values('$url[$i]','$text[$i]','$date[$i]','$content','$fbrq')";
                $rs =mysql_query($sql,$link);
                        if($rs ==false){
                        echo "<font color=red>false!".$url[$i]."</font><br />";
                }else{
                        echo "ok!".$url[$i]."<br />";
                }
                }
}
}
for($i=$j;$i>-1;$i--){ //通过循环分析所有的页面
        if($i==0){
                $page ="http://it.rising.com.cn/Channels/Anti_Virus/Virus_Week/index.shtml";
        }else{
                $page ="http://it.rising.com.cn/Channels/Anti_Virus/Virus_Week/index_".$i.".shtml";
        }
        insert_to_db($page);       
}


?>

作者: morsth   发布时间: 2007-07-23

:L 比较高深

作者: pack08   发布时间: 2007-07-23

写的有些乱了,不好意思献丑了。很简单的,就是用正则表达式匹配了。

作者: morsth   发布时间: 2007-07-23

看了也等于没看不懂:L

作者: maikongjian11   发布时间: 2007-07-27

强・・・・・・・・

作者: 疯子-斯   发布时间: 2007-08-29

十分不错.但最好能加点注释.这样能让大家更好的阅读吸收

加上注释.我给LZ加亮帖子:)

作者: 逆雪寒   发布时间: 2007-08-30

采集嘛。。。加油~

作者: scauren   发布时间: 2007-08-30

恩不错的东东!

作者: forest   发布时间: 2007-08-30

有滴那意思...........

作者: londit.cn   发布时间: 2007-09-06

支持!
oa库结构也不给一个?

作者: redcolt   发布时间: 2007-09-12