当前位置: 移动技术网 > IT编程>开发语言>PHP > 教你如何用php实现LOL数据远程获取

教你如何用php实现LOL数据远程获取

2019年06月03日  | 移动技术网IT编程  | 我要评论

李天熙老婆,赛尔号火山星,利物浦大学

过几天网站就要上线了。

最近完成了一个小功能,就是lol数据获取,

比如:我给你一个号,你把这个号是否打过排位?战斗力是多少?胜率和所在的总场数数据获取过来

数据都在多玩的网站上可查,所以该做的功能就是远程抓取。

功能没啥亮点,就是简单的实现。

反正就是js不能跨域,然后用php去跨域,用file_get_content好类或者是curl好,都不重要。重要是的能理解业务流程。

上面这个图就是执行业务流程图。清楚流程了,然后代码就好写了

当然说了,这里就,重点是php怎么去抓取数据的。

这里要介绍一款非常好的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");       //数据抓取类
        $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。
上面这个类很简单,难点在于怎么去分析多玩查询页面的数据。用firebug看看吧。
写多了,你就知道的了。当然了,你想查询rank隐藏分数,也是可以滴,不过要去马化腾网站去获取数据了,这里就不详细说明了,提供个思路就可以了

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网