|
過幾天網(wǎng)站就要上線了。
最近完成了一個(gè)小功能,就是LOL數(shù)據(jù)獲取,
比如:我給你一個(gè)號(hào),你把這個(gè)號(hào)是否打過排位?戰(zhàn)斗力是多少?勝率和所在的總場(chǎng)數(shù)數(shù)據(jù)獲取過來
數(shù)據(jù)都在多玩的網(wǎng)站上可查,所以該做的功能就是遠(yuǎn)程抓取。
功能沒啥亮點(diǎn),就是簡(jiǎ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(自行百度獲取文檔)
復(fù)制代碼 代碼如下:
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) ;
}
上面這些代碼,暴露了哥英語過了四級(jí)但還是硬傷的BUG。
上面這個(gè)類很簡(jiǎn)單,難點(diǎn)在于怎么去分析多玩查詢頁面的數(shù)據(jù)。用firebug看看吧。
寫多了,你就知道的了。當(dāng)然了,你想查詢r(jià)ank隱藏分?jǐn)?shù),也是可以滴,不過要去馬化騰網(wǎng)站去獲取數(shù)據(jù)了,這里就不詳細(xì)說明了,提供個(gè)思路就可以了
php技術(shù):教你如何用php實(shí)現(xiàn)LOL數(shù)據(jù)遠(yuǎn)程獲取,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。