zoukankan      html  css  js  c++  java
  • PHP 小方法之 仿百度蜘蛛采集

    if(!function_exists('_GetContent')){
         function _GetContent( $url ){
            $ch = curl_init();
            $ip = '220.181.108.91';  // 百度蜘蛛
            $timeout = 15;
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_TIMEOUT,0);
            //伪造百度蜘蛛IP
            curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-FORWARDED-FOR:'.$ip.'','CLIENT-IP:'.$ip.''));
            //伪造百度蜘蛛头部
            curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)");
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch,CURLOPT_HEADER,0);
            curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
            $content = curl_exec($ch);
            if($content === false)
            {//输出错误信息
                $no = curl_errno($ch);
                switch(trim($no))
                {
                    case 28 : $error = '访问目标地址超时'; break;
                    default : $error = curl_error($ch); break;
                }
                echo $error;
            }
            else
            {
                $succ = true;
                return $content;
            }
        }
    }
  • 相关阅读:
    nohup 运行后台程序
    配置了yum本地源
    rhel 6.7 离线安装docker
    java timer 执行任务
    遇到的sql关键字
    mysql事务和锁
    Mysql命令大全
    mysql keepalived
    mysql主从复制
    mysql从binlog恢复数据
  • 原文地址:https://www.cnblogs.com/zouzhe0/p/6202939.html
Copyright © 2011-2022 走看看