php抓取百度链接 | 网赚,网络营销,seo优化和网络安全-骚鱼博客
0

php抓取百度链接

已有 1,974 人阅读此文 - -

虽然有工具但是都没有开源的 百度一边规则 就没法玩了

这个方便 规则变了 改改就成 直接上代码 php抓取百度链接

<?php
    error_reporting(E_ERROR);
    set_time_limit(0);
    $keyword = '爱情' ; // 批量关键字
    $filedir= "test.txt";
    $timeout = 20; 
    $startpage = 1; 
    $lastpage = 4; // [url]http://hi.baidu.com/sethc5/blog[/url]
    $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
 function ReadBaiduList($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.1\r\nHost:[url]www.baidu.com[/url]\r\nConnection: Close\r\n\r\n");
        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;
 }

?>
0
相关文章!