亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        教你如何用php實(shí)現(xiàn)lol數(shù)據(jù)遠(yuǎn)程獲取

        字號:


            過幾天網(wǎng)站就要上線了。
            最近完成了一個(gè)小功能,就是lol數(shù)據(jù)獲取,
            比如:我給你一個(gè)號,你把這個(gè)號是否打過排位?戰(zhàn)斗力是多少?勝率和所在的總場數(shù)數(shù)據(jù)獲取過來
            數(shù)據(jù)都在多玩的網(wǎng)站上可查,所以該做的功能就是遠(yuǎn)程抓取。
            功能沒啥亮點(diǎn),就是簡單的實(shí)現(xiàn)。
            反正就是js不能跨域,然后用php去跨域,用file_get_content好類或者是curl好,都不重要。重要是的能理解業(yè)務(wù)流程。
            上面這個(gè)圖就是執(zhí)行業(yè)務(wù)流程圖。清楚流程了,然后代碼就好寫了
            當(dāng)然說了,這里就,重點(diǎn)是php怎么去抓取數(shù)據(jù)的。
            這里要介紹一款非常好的php類,simple_html_dom(自行百度獲取文檔)
            代碼如下:
            public function getdata(){
            $server = isset($_post['gameserver'])?trim($_post['gameserver']):null;
            $name = isset($_post['gamename'])?trim($_post['gamename']):null;
            import(@.org.simplehtmldom); //數(shù)據(jù)抓取類
            $url = http://lolbox.duowan.com/playerdetail.php?servername=.urlencode($server).&playername=.urlencode($name);
            $html = file_get_html($url);
            $dom = $html->find('.fighting',0)->children(1);
            $result['zdl'] = strip_tags($dom->innertext);
            $doms = $html->find('.j_content',0)->children(1);
            //echo $html->find(#ranked_tier,0)->innertext;
            $temp = $doms->plaintext;
            $temparray = explode( ,trim($temp));
            foreach($temparray as $key=>$value)
            {
            if(!empty($value))
            {
            $temparr[] = trim($value);
            }
            }
            unset($temparray);
            //獲取排位類型
            $pwtype = $temparr[8];
            $pwtotal = $temparr[12];
            $pwsl = $temparr[14];
            if($pwtype == 5v5單雙排)
            {
            $result['pw'] = $pwtotal;
            $result['pwsl'] = $pwsl;
            }else{
            $result['pw'] = 0;
            $result['pwsl'] = 0;
            }
            $this->ajaxreturn($result) ;
            }
            上面這些代碼,暴露了哥英語過了四級但還是硬傷的bug。
            上面這個(gè)類很簡單,難點(diǎn)在于怎么去分析多玩查詢頁面的數(shù)據(jù)。用firebug看看吧。