天天看點

php http請求類

  1. 代碼:
    <?php
    namespace dollarphp;
    /**
    * @desc:http請求類
    * @author [Lee] <[<[email protected]>]>
    * @property
    * 1、timeout    逾時時間,預設5秒
    * 2、depth      重定向深度,預設3
    * 3、name       上傳檔案的名字,預設file
    * 4、cookie     模拟登入時cookie存儲在本地的檔案,預設cookie.txt
    * @method
    * 1、ssl        是否設定https           true:是  false:否
    * 2、auth       啟用驗證                user:使用者名    pass:密碼
    * 3、login      模拟登入,擷取cookie
    * 4、cookie     使用cookie登入
    * 5、header     設定請求頭              data:請求頭數組
    * 6、proxy      設定伺服器代理          url:代理伺服器url   port:代理伺服器端口
    * 7、agent      設定浏覽器代理          browse:代理浏覽器 預設:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
    * 8、get        模拟get請求             data:傳遞的資料
    * 9、post       模拟post請求            data:傳遞的資料
    * 10、json      模拟json請求            data:傳遞的資料
    * 11、upload    模拟表單上傳            files:上傳的檔案   array|string
    * 12、download  下載下傳檔案                dir:要下載下傳的檔案  格式:a/b
    * 13、run       執行                    ret:傳回的資料
    * 14、info      擷取執行資訊            ret:傳回的資訊
    */
    class http{
    public $timeout = 5;  #  逾時時間,預設5秒
    public $depth = 3;  #  重定向深度,預設3
    public $name = 'file';  #  上傳檔案的名字,預設file
    public $cookie = 'cookie.txt';  #  模拟登入時cookie存儲在本地的檔案,預設cookie_n
    private $scheme = '';
    private $host = '';
    private $path = '';
    private $query = '';
    private $options = array();
    private $ch;
    private $fp;
    private $progress = false;
    /*
     @desc:内部方法 設定get請求參數
     @param data 請求資料
     */
    private function setget($data){
        $scheme = $this->scheme;
        $host = $this->host;
        $path = $this->path;
        $query = $this->query;
        $sep = ($query || !empty($data))?"?":"";
        $qurl = $scheme.'://'.$host.$path.$sep.$query.$data;
        $this->options[CURLOPT_URL] = $qurl;
        return $this;
    }
    /*
     @desc:内部方法 設定post請求參數
     @param data 請求資料
     */
    private function setpost($data){
        $scheme = $this->scheme;
        $host = $this->host;
        $path = $this->path;
        $query = $this->query;
        $sep = $query?"?":"";
        $qurl = $scheme.'://'.$host.$path.$sep.$query;
        $this->options[CURLOPT_URL] = $qurl;
        $this->options[CURLOPT_POST] = 1;
        $this->options[CURLOPT_POSTFIELDS] = $data;
        return $this;
    }
    /*
     @desc:内部方法 設定最終請求參數
     */
    private function setopt(){
        $options = $this->options;
        curl_setopt_array(
                $this->ch,
                $options
            );
        return $this;
    }
    /*
     @desc:構造方法 設定初始請求參數
     @param url 請求位址
     */
    public function __construct($url){
        $info = parse_url($url);
        $this->scheme = $info['scheme']?:'http';
        $this->host = $info['host'];
        $this->path = $info['path'];
        $this->query = $info['query'];
        $this->ch = curl_init();
        $this->options[CURLOPT_CONNECTTIMEOUT] = $this->timeout;
        $this->options[CURLOPT_RETURNTRANSFER] = 1;
        $this->options[CURLOPT_FOLLOWLOCATION] = 1;
        $this->options[CURLINFO_HEADER_OUT] = true;
        $this->options[CURLOPT_ENCODING] = 'gzip';
        $this->options[CURLOPT_MAXREDIRS] = $this->depth;
    }
    /*
     @desc:是否設定https請求
     @param bool true:https請求 false:http請求
     */
    public function ssl($bool = false){
        if($bool){
            $this->scheme = 'https';
            $this->options[CURLOPT_SSL_VERIFYHOST] = 1;
            $this->options[CURLOPT_SSL_VERIFYPEER] = false;
        }
        return $this;
    }
    /*
     @desc:設定驗證使用者名、密碼
     @param user 使用者名
     @param pass 密碼
     */
    public function auth($user,$pass){
        $this->options[CURLOPT_USERPWD] = $user.':'.$pass;
        return $this;
    }
    /*
     @desc:模拟登入
     */
    public function login(){
        $cookie = $this->cookie;
        $this->options[CURLOPT_COOKIEJAR] = $cookie;
        $this->options[CURLOPT_RETURNTRANSFER] = 0;
        return $this;
    }
    /*
     @desc:帶cookie登入
     */
    public function cookie(){
        $cookie = $this->cookie;
        $this->options[CURLOPT_COOKIEFILE] = $cookie;
        return $this;
    }
    /*
     @desc:設定請求頭資訊
     @param data 請求頭
     */
    public function header($data){
        $this->options[CURLOPT_HTTPHEADER] = $this->options[CURLOPT_HTTPHEADER]?:array();
        $this->options[CURLOPT_HTTPHEADER] = array_merge($this->options[CURLOPT_HTTPHEADER],$data);
        return $this;
    }
    /*
     @desc:設定代理伺服器
     @param url 代理伺服器url
     @param port 代理伺服器端口
     */
    public function proxy($url,$port){
        $info = parse_url($url);
        $scheme = $info['scheme']?:'http';
        $host = $info['host'];
        $path = $info['path'];
        $purl = $scheme.'://'.$host.$path.':'.$port;
        $this->options[CURLOPT_PROXY] = $purl;
        return $this;
    }
    /*
     @desc:設定代理浏覽器
     @param browse 代理浏覽器
     */
    public function agent($browse = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)'){
        $this->options[CURLOPT_USERAGENT] = $browse;
        return $this;
    }
    /*
     @desc:模拟get請求
     @param data 請求資料
     */
    public function get($data = array()){
        $data = http_build_query($data);
        $this->setget($data);
        return $this;
    }
    /*
     @desc:模拟post請求
     @param data 請求資料
     */
    public function post($data = array()){
        $this->setpost($data);
        return $this;
    }
    /*
     @desc:模拟json請求
     @param data 請求資料
     */
    public function json($data = array()){
        $data = json_encode($data);
        $header = array(
                'Content-Type: application/json',
                'Content-Length:' . strlen($data)
            );
        $this->header($header);
        $this->setpost($data);
        return $this;
    }
    /*
     @desc:模拟表單上傳
     @param files 檔案路徑
     */
    public function upload($files){
        $this->progress = true;
        $data = array();
        $name = $this->name;
        if(is_array($files)){
            foreach($files as $k=>$v){
                $data["{$name}[{$k}]"]=new \CURLFile($v);
            }
        }else{
            $data["{$name}"]=new \CURLFile($files);
        }
        ob_start();
        echo ">>";
        ob_flush();
        flush();
        $last = 0;
        $diff = 0;
        $this->options[CURLOPT_PROGRESSFUNCTION] = function($source,$dfilesize,$downsize,$upsize,$ufilesize){
            global $last;
            global $diff;
            if($ufilesize > 0){
                $percent = round($ufilesize/$upsize*100,2);
                $diff += $percent - $last;
                if($diff > 1){
                    echo "#";
                    $diff = 0;
                }
                $last = $percent;
            }
            ob_flush();
            flush();
        };
        $this->options[CURLOPT_NOPROGRESS] = false;
        $this->setpost($data);
        return $this;
    }
    /*
     @desc:下載下傳檔案
     @param dir 存儲檔案目錄
     */
    public function download($dir = ''){
        $this->progress = true;
        $path = $this->path;
        if($dir && !is_dir($dir)){
            mkdir($dir,0755,true);
        }
        $name = strrchr($path, '/');
        $dsep = $dir?'/':'';
        ob_start();
        echo ">>";
        ob_flush();
        flush();
        $this->fp=fopen('.'.$dsep.$dir.$name, 'w');
        $last = 0;
        $diff = 0;
        $this->options[CURLOPT_PROGRESSFUNCTION] = function($source,$dfilesize,$downsize,$upsize,$ufilesize){
            global $last;
            global $diff;
            if($dfilesize > 0){
                $percent = round($downsize/$dfilesize*100,2);
                $diff += $percent - $last;
                if($diff > 1){
                    echo "#";
                    $diff = 0;
                }
                $last = $percent;
            }
            ob_flush();
            flush();
        };
        $this->options[CURLOPT_NOPROGRESS] = false;
        $this->options[CURLOPT_FILE] = $this->fp;
        $this->setget('');
        return $this;
    }
    /*
     @desc:執行方法
     @return ret 傳回的資料
     */
    public function run(){
        $ch = $this->ch;
        $this->setopt();
        $ret = curl_exec($ch);
        curl_close($ch);
        if($this->progress){
            if($this->fp){
                fclose($this->fp);
            }
            echo "#<<done";
            ob_flush();
            flush();
        }
        return $ret;
    }
    /*
     @desc:擷取執行資訊
     @return ret 傳回的資訊
     */
    public function info(){
        $ch = $this->ch;
        $this->setopt();
        curl_exec($ch);
        $ret = curl_getinfo($ch);
        curl_close($ch);
        if($this->fp){
            fclose($this->fp);
        }
        return $ret;
    }
    }           
  2. 測試:
    $http = new http('www.baidu.com');
    $ret = $http->ssl(true)->get()->run();
    echo $ret;           
  3. 輸出:
    <!DOCTYPE html><!--STATUS OK-->
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <link rel="dns-prefetch" href="//s1.bdstatic.com"/>
    <link rel="dns-prefetch" href="//t1.baidu.com"/>
    <link rel="dns-prefetch" href="//t2.baidu.com"/>
    <link rel="dns-prefetch" href="//t3.baidu.com"/>
    <link rel="dns-prefetch" href="//t10.baidu.com"/>
    <link rel="dns-prefetch" href="//t11.baidu.com"/>
    <link rel="dns-prefetch" href="//t12.baidu.com"/>
    <link rel="dns-prefetch" href="//b1.bdstatic.com"/>
    <title>百度一下,你就知道</title>
    <link href="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/home/css/index.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 8]><style index="index" >#content{height:480px\9}#m{top:260px\9}</style><![endif]-->
    <!--[if IE 8]><style index="index" >#u1 a.mnav,#u1 a.mnav:visited{font-family:simsun}</style><![endif]-->
    <script>var hashMatch = document.location.href.match(/#+(.*wd=[^&].+)/);if (hashMatch && hashMatch[0] && hashMatch[1]) {document.location.replace("http://"+location.host+"/s?"+hashMatch[1]);}var ns_c = function(){};</script>
    <script>function h(obj){obj.style.behavior='url(#default#homepage)';var a = obj.setHomePage('//www.baidu.com/');}</script>
    <noscript><meta http-equiv="refresh" content="0; url=/baidu.html?from=noscript"/></noscript>
    <script>window._ASYNC_START=new Date().getTime();</script>
    </head>
    <body link="#0000cc"><div id="wrapper" style="display:none;"><div id="u"><a rel="nofollow" href="//www.baidu.com/gaoji/preferences.html"  onmousedown="return user_c({'fm':'set','tab':'setting','login':'0'})">搜尋設定</a>|<a rel="nofollow" id="btop" href="/"  onmousedown="return user_c({'fm':'set','tab':'index','login':'0'})">百度首頁</a>|<a rel="nofollow" id="lb" href="https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F" onclick="return false;"  onmousedown="return user_c({'fm':'set','tab':'login'})">登入</a><a rel="nofollow" href="https://passport.baidu.com/v2/?reg®Type=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F"  onmousedown="return user_c({'fm':'set','tab':'reg'})" target="_blank" class="reg">注冊</a></div><div id="head"><div class="s_nav"><a rel="nofollow" href="/" class="s_logo" onmousedown="return c({'fm':'tab','tab':'logo'})"><img src="//www.baidu.com/img/baidu_jgylogo3.gif" width="117" height="38" border="0" alt="到百度首頁" title="到百度首頁"></a><div class="s_tab" id="s_tab"><a rel="nofollow" href="http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=" wdfield="word"  onmousedown="return c({'fm':'tab','tab':'news'})">新聞</a> <b>網頁</b> <a rel="nofollow" href="http://tieba.baidu.com/f?kw=&fr=wwwt" wdfield="kw"  onmousedown="return c({'fm':'tab','tab':'tieba'})">貼吧</a> <a rel="nofollow" href="http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word=&fr=wwwt" wdfield="word"  onmousedown="return c({'fm':'tab','tab':'zhidao'})">知道</a> <a rel="nofollow" href="http://music.baidu.com/search?fr=ps&key=" wdfield="key"  onmousedown="return c({'fm':'tab','tab':'music'})">音樂</a> <a rel="nofollow" href="http://image.baidu.com/i?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&word=" wdfield="word"  onmousedown="return c({'fm':'tab','tab':'pic'})">圖檔</a> <a rel="nofollow" href="http://v.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=25&word=" wdfield="word"   onmousedown="return c({'fm':'tab','tab':'video'})">視訊</a> <a rel="nofollow" href="http://map.baidu.com/m?word=&fr=ps01000" wdfield="word"  onmousedown="return c({'fm':'tab','tab':'map'})">地圖</a> <a rel="nofollow" href="http://wenku.baidu.com/search?word=&lm=0&od=0" wdfield="word"  onmousedown="return c({'fm':'tab','tab':'wenku'})">文庫</a> <a rel="nofollow" href="//www.baidu.com/more/"  onmousedown="return c({'fm':'tab','tab':'more'})">更多»</a></div></div><form id="form" name="f" action="/s" class="fm" ><input type="hidden" name="ie" value="utf-8"><input type="hidden" name="f" value="8"><input type="hidden" name="rsv_bp" value="1"><span class="bg s_ipt_wr"><input name="wd" id="kw" class="s_ipt" value="" maxlength="100"></span><span class="bg s_btn_wr"><input type="submit" id="su" value="百度一下" class="bg s_btn" onmousedown="this.className='bg s_btn s_btn_h'" onmouseout="this.className='bg s_btn'"></span><span class="tools"><span id="mHolder"><div id="mCon"><span>輸入法</span></div><ul id="mMenu"><li><a rel="nofollow" href="javascript:;" name="ime_hw">手寫</a></li><li><a rel="nofollow" href="javascript:;" name="ime_py">拼音</a></li><li class="ln"></li><li><a rel="nofollow" href="javascript:;" name="ime_cl">關閉</a></li></ul></span><span class="shouji"><strong>推薦 : </strong><a rel="nofollow" href="http://w.x.baidu.com/go/mini/8/10000020" onmousedown="return ns_c({'fm':'behs','tab':'bdbrowser'})">百度浏覽器,打開網頁快2秒!</a></span></span></form></div><div id="content"><div id="u1"><a rel="nofollow" href="http://news.baidu.com" name="tj_trnews" class="mnav">新聞</a><a rel="nofollow" href="http://www.hao123.com" name="tj_trhao123" class="mnav">hao123</a><a rel="nofollow" href="http://map.baidu.com" name="tj_trmap" class="mnav">地圖</a><a rel="nofollow" href="http://v.baidu.com" name="tj_trvideo" class="mnav">視訊</a><a rel="nofollow" href="http://tieba.baidu.com" name="tj_trtieba" class="mnav">貼吧</a><a rel="nofollow" href="https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F" name="tj_login" id="lb" onclick="return false;">登入</a><a rel="nofollow" href="//www.baidu.com/gaoji/preferences.html" name="tj_settingicon" id="pf">設定</a><a rel="nofollow" href="//www.baidu.com/more/" name="tj_briicon" id="bri">更多産品</a></div><div id="m"><p id="lg"><img src="//www.baidu.com/img/bd_logo.png" width="270" height="129"></p><p id="nv"><a rel="nofollow" href="http://news.baidu.com">新 聞</a> <b>網 頁</b> <a rel="nofollow" href="http://tieba.baidu.com">貼 吧</a> <a rel="nofollow" href="http://zhidao.baidu.com">知 道</a> <a rel="nofollow" href="http://music.baidu.com">音 樂</a> <a rel="nofollow" href="http://image.baidu.com">圖 片</a> <a rel="nofollow" href="http://v.baidu.com">視 頻</a> <a rel="nofollow" href="http://map.baidu.com">地 圖</a></p><div id="fm"><form id="form1" name="f1" action="/s" class="fm"><span class="bg s_ipt_wr"><input type="text" name="wd" id="kw1" maxlength="100" class="s_ipt"></span><input type="hidden" name="rsv_bp" value="0"><input type=hidden name=ch value=""><input type=hidden name=tn value="baidu"><input type=hidden name=bar value=""><input type="hidden" name="rsv_spt" value="3"><input type="hidden" name="ie" value="utf-8"><span class="bg s_btn_wr"><input type="submit" value="百度一下" id="su1" class="bg s_btn" onmousedown="this.className='bg s_btn s_btn_h'" onmouseout="this.className='bg s_btn'"></span></form><span class="tools"><span id="mHolder1"><div id="mCon1"><span>輸入法</span></div></span></span><ul id="mMenu1"><div class="mMenu1-tip-arrow"><em></em><ins></ins></div><li><a rel="nofollow" href="javascript:;" name="ime_hw">手寫</a></li><li><a rel="nofollow" href="javascript:;" name="ime_py">拼音</a></li><li class="ln"></li><li><a rel="nofollow" href="javascript:;" name="ime_cl">關閉</a></li></ul></div><p id="lk"><a rel="nofollow" href="http://baike.baidu.com">百科</a> <a rel="nofollow" href="http://wenku.baidu.com">文庫</a> <a rel="nofollow" href="http://www.hao123.com">hao123</a><span> | <a rel="nofollow" href="//www.baidu.com/more/">更多>></a></span></p><p id="lm"></p></div></div><div id="ftCon"><div id="ftConw"><p id="lh"><a rel="nofollow" id="seth" onClick="h(this)" href="/" onmousedown="return ns_c({'fm':'behs','tab':'homepage','pos':0})">把百度設為首頁</a><a rel="nofollow" id="setf" href="//www.baidu.com/cache/sethelp/index.html" onmousedown="return ns_c({'fm':'behs','tab':'favorites','pos':0})" target="_blank">把百度設為首頁</a><a rel="nofollow" onmousedown="return ns_c({'fm':'behs','tab':'tj_about'})" href="http://home.baidu.com">關于百度</a><a rel="nofollow" onmousedown="return ns_c({'fm':'behs','tab':'tj_about_en'})" href="http://ir.baidu.com">About Baidu</a></p><p id="cp">©2018 Baidu <a rel="nofollow" href="/duty/" name="tj_duty">使用百度前必讀</a> 京ICP證030173号 <img src="http://s1.bdstatic.com/r/www/cache/static/global/img/gs_237f015b.gif"></p></div></div><div id="wrapper_wrapper"></div></div><div class="c-tips-container" id="c-tips-container"></div>
    <script>window.__async_strategy=2;</script>
    <script>var bds={se:{},su:{urdata:[],urSendClick:function(){}},util:{},use:{},comm : {domain:"http://www.baidu.com",ubsurl : "http://sclick.baidu.com/w.gif",tn:"baidu",queryEnc:"",queryId:"",inter:"",templateName:"baidu",sugHost : "http://suggestion.baidu.com/su",query : "",qid : "",cid : "",sid : "",indexSid : "",stoken : "",serverTime : "",user : "",username : "",loginAction : [],useFavo : "",pinyin : "",favoOn : "",curResultNum:"",rightResultExist:false,protectNum:0,zxlNum:0,pageNum:1,pageSize:10,newindex:0,async:1,maxPreloadThread:5,maxPreloadTimes:10,preloadMouseMoveDistance:5,switchAddMask:false,isDebug:false,ishome : 1},_base64:{domain : "http://b1.bdstatic.com/",b64Exp : -1,pdc : 0}};var name,navigate,al_arr=[];var selfOpen = window.open;eval("var open = selfOpen;");var isIE=navigator.userAgent.indexOf("MSIE")!=-1&&!window.opera;var E = bds.ecom= {};bds.se.mon = {'loadedItems':[],'load':function(){},'srvt':-1};try {bds.se.mon.srvt = parseInt(document.cookie.match(new RegExp("(^| )BDSVRTM=([^;]*)(;|$)"))[2]);document.cookie="BDSVRTM=;expires=Sat, 01 Jan 2000 00:00:00 GMT"; }catch(e){}</script>
    <script>if(!location.hash.match(/[^a-zA-Z0-9]wd=/)){document.getElementById("ftCon").style.display='block';document.getElementById("u1").style.display='block';document.getElementById("content").style.display='block';document.getElementById("wrapper").style.display='block';setTimeout(function(){try{document.getElementById("kw1").focus();document.getElementById("kw1").parentNode.className += ' iptfocus';}catch(e){}},0);}</script>
    <script type="text/javascript" src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/jquery/jquery-1.10.2.min_f2fb5194.js"></script>
    <script>(function(){var index_content = $('#content');var index_foot= $('#ftCon');var index_css= $('head [index]');var index_u= $('#u1');var result_u= $('#u');var wrapper=$("#wrapper");window.index_on=function(){index_css.insertAfter("meta:eq(0)");result_common_css.remove();result_aladdin_css.remove();result_sug_css.remove();index_content.show();index_foot.show();index_u.show();result_u.hide();wrapper.show();if(bds.su&&bds.su.U&&bds.su.U.homeInit){bds.su.U.homeInit();}setTimeout(function(){try{$('#kw1').get(0).focus();window.sugIndex.start();}catch(e){}},0);if(typeof initIndex=='function'){initIndex();}};window.index_off=function(){index_css.remove();index_content.hide();index_foot.hide();index_u.hide();result_u.show();result_aladdin_css.insertAfter("meta:eq(0)");result_common_css.insertAfter("meta:eq(0)");result_sug_css.insertAfter("meta:eq(0)");wrapper.show();};})();</script>
    <script>window.__switch_add_mask=1;</script>
    <script type="text/javascript" src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/global/js/instant_search_newi_redirect1_20bf4036.js"></script>
    <script>initPreload();$("#u,#u1").delegate("#lb",'click',function(){try{bds.se.login.open();}catch(e){}});if(navigator.cookieEnabled){document.cookie="NOJS=;expires=Sat, 01 Jan 2000 00:00:00 GMT";}</script>
    <script>$(function(){for(i=0;i<3;i++){u($($('.s_ipt_wr')[i]),$($('.s_ipt')[i]),$($('.s_btn_wr')[i]),$($('.s_btn')[i]));}function u(iptwr,ipt,btnwr,btn){if(iptwr && ipt){iptwr.on('mouseover',function(){iptwr.addClass('ipthover');}).on('mouseout',function(){iptwr.removeClass('ipthover');}).on('click',function(){ipt.focus();});ipt.on('focus',function(){iptwr.addClass('iptfocus');}).on('blur',function(){iptwr.removeClass('iptfocus');}).on('render',function(e){var $s = iptwr.parent().find('.bdsug');var l = $s.find('li').length;if(l>=5){$s.addClass('bdsugbg');}else{$s.removeClass('bdsugbg');}});}if(btnwr && btn){btnwr.on('mouseover',function(){btn.addClass('btnhover');}).on('mouseout',function(){btn.removeClass('btnhover');});}}});</script>
    <script type="text/javascript" src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/home/js/bri_7f1fa703.js"></script>
    <script>(function(){var _init=false;window.initIndex=function(){if(_init){return;}_init=true;var w=window,d=document,n=navigator,k=d.f1.wd,a=d.getElementById("nv").getElementsByTagName("a"),isIE=n.userAgent.indexOf("MSIE")!=-1&&!window.opera;(function(){if(/q=([^&]+)/.test(location.search)){k.value=decodeURIComponent(RegExp["\x241"])}})();(function(){var u = G("u1").getElementsByTagName("a"), nv = G("nv").getElementsByTagName("a"), lk = G("lk").getElementsByTagName("a"), un = "";var tj_nv = ["news","tieba","zhidao","mp3","img","video","map"];var tj_lk = ["baike","wenku","hao123","more"];un = bds.comm.user == "" ? "" : bds.comm.user;function _addTJ(obj){addEV(obj, "mousedown", function(e){var e = e || window.event;var target = e.target || e.srcElement;if(target.name){ns_c({'fm':'behs','tab':target.name,'un':encodeURIComponent(un)});}});}for(var i = 0; i < u.length; i++){_addTJ(u[i]);}for(var i = 0; i < nv.length; i++){nv[i].name = 'tj_' + tj_nv[i];}for(var i = 0; i < lk.length; i++){lk[i].name = 'tj_' + tj_lk[i];}})();(function() {var links = {'tj_news': ['word', 'http://news.baidu.com/ns?tn=news&cl=2&rn=20&ct=1&ie=utf-8'],'tj_tieba': ['kw', 'http://tieba.baidu.com/f?ie=utf-8'],'tj_zhidao': ['word', 'http://zhidao.baidu.com/search?pn=0&rn=10&lm=0'],'tj_mp3': ['key', 'http://music.baidu.com/search?fr=ps&ie=utf-8'],'tj_img': ['word', 'http://image.baidu.com/i?ct=201326592&cl=2&nc=1&lm=-1&st=-1&tn=baiduimage&istype=2&fm=&pv=&z=0&ie=utf-8'],'tj_video': ['word', 'http://video.baidu.com/v?ct=301989888&s=25&ie=utf-8'],'tj_map': ['wd', 'http://map.baidu.com/?newmap=1&ie=utf-8&s=s'],'tj_baike': ['word', 'http://baike.baidu.com/search/word?pic=1&sug=1&enc=utf8'],'tj_wenku': ['word', 'http://wenku.baidu.com/search?ie=utf-8']};var domArr = [G('nv'), G('lk'),G('cp')],kw = G('kw1');for (var i = 0, l = domArr.length; i < l; i++) {domArr[i].onmousedown = function(e) {e = e || window.event;var target = e.target || e.srcElement,name = target.getAttribute('name'),items = links[name],reg = new RegExp('^\\s+|\\s+\x24'),key = kw.value.replace(reg, '');if (items) {if (key.length > 0) {var wd = items[0], url = items[1],url = url + ( name === 'tj_map' ? encodeURIComponent('&' + wd + '=' + key) : ( ( url.indexOf('?') > 0 ? '&' : '?' ) + wd + '=' + encodeURIComponent(key) ) );target.href = url;} else {target.href = target.href.match(new RegExp('^http:\/\/.+\.baidu\.com'))[0];}}name && ns_c({'fm': 'behs','tab': name,'query': encodeURIComponent(key),'un': encodeURIComponent(bds.comm.user || '') });};}})();};if(window.pageState==0){initIndex();}})();document.cookie = 'IS_STATIC=1;expires=' + new Date(new Date().getTime() + 10*60*1000).toGMTString();</script>
    </body></html>