php关键词抓取链接源码

  • A+
所属分类:安全文章

<?php


    error_reporting(E_ERROR);


    set_time_limit(0);


    $keyword= '飓风'; // 批量关键字


    $filedir= "test.txt";


    $timeout= 20; 


    $startpage= 1; 


    $lastpage= 4; //


    $list= ReadBaiduList($keyword,$timeout,$startpage,$lastpage);


    $num= count($list);


    $fp= fopen("$filedir",w);


    if($fp) {


        for($i=0;$i<=$num;$i++) {


            fwrite($fp,$list[$i]."n");


        }


    }else{


        echo'<font color=red>can not open file';


    }


    fclose($fp);


 


//http://www.baidu.com/s?wd=飓风&pn=40&ie=utf-8&usm=1


functionReadBaiduList($keyword,$timeout,$startpage,$lastpage) {


   for($i=$startpage; $i<$lastpage; $i++) {


        $nowpage= ($i-1)*10;


        $fp= @fsockopen('www.baidu.com',80,$errno,$errstr,$timeout);


        @fputs($fp,"GET /s?wd=".urlencode($keyword)."&pn=".$nowpage." HTTP/1.1rnHost:

rnConnection: Closernrn");


        while($fp&& !feof($fp))


        $data.= fread($fp, 1024);


        @fclose($fp);


        preg_match_all("/<span class="g">(.*)</span>/iU",$data,$tmp);


    }


        foreach($tmp[1] as$value) {


            $list= explode('/',$value);


            $lastlist[] = $list[0];


        }


        $lastlist= array_unique($lastlist);


        return$lastlist;


 }


 


?>


本文始发于微信公众号(飓风网络安全):php关键词抓取链接源码

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: