教你如何用php實現(xiàn)lol數(shù)據(jù)遠程獲取
來源:易賢網 閱讀:1268 次 日期:2014-10-08 13:51:43
溫馨提示:易賢網小編為您整理了“教你如何用php實現(xiàn)lol數(shù)據(jù)遠程獲取”,方便廣大網友查閱!

過幾天網站就要上線了。

最近完成了一個小功能,就是lol數(shù)據(jù)獲取,

比如:我給你一個號,你把這個號是否打過排位?戰(zhàn)斗力是多少?勝率和所在的總場數(shù)數(shù)據(jù)獲取過來

數(shù)據(jù)都在多玩的網站上可查,所以該做的功能就是遠程抓取。

功能沒啥亮點,就是簡單的實現(xiàn)。

反正就是js不能跨域,然后用php去跨域,用file_get_content好類或者是curl好,都不重要。重要是的能理解業(yè)務流程。

上面這個圖就是執(zhí)行業(yè)務流程圖。清楚流程了,然后代碼就好寫了

當然說了,這里就,重點是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。

上面這個類很簡單,難點在于怎么去分析多玩查詢頁面的數(shù)據(jù)。用firebug看看吧。

更多信息請查看IT技術專欄

更多信息請查看網絡編程

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網