源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-05-01 20:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:教你如何用php实现LOL数据远程获取
过几天网站就要上线了。 最近完成了一个小功能,就是LOL数据获取, 比如:我给你一个号,你把这个号是否打过排位?战斗力是多少?胜率和所在的总场数数据获取过来 数据都在多玩的网站上可查,所以该做的功能就是远程抓取。 [img]http://files.jb51.net/file_images/article/201406/201461095128267.png?201451095141[/img] 功能没啥亮点,就是简单的实现。 反正就是JS不能跨域,然后用PHP去跨域,用file_get_content好类或者是curl好,都不重要。重要是的能理解业务流程。 [img]http://files.jb51.net/file_images/article/201406/201461095153515.png?20145109524[/img] 上面这个图就是执行业务流程图。清楚流程了,然后代码就好写了 当然说了,这里就,重点是PHP怎么去抓取数据的。 这里要介绍一款非常好的PHP类,Simple_html_dom(自行百度获取文档)
[u]复制代码[/u] 代码如下:
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隐藏分数,也是可以滴,不过要去马化腾网站去获取数据了,这里就不详细说明了,提供个思路就可以了
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部