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

過(guò)幾天網(wǎng)站就要上線了。

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

比如:我給你一個(gè)號(hào),你把這個(gè)號(hào)是否打過(guò)排位?戰(zhàn)斗力是多少?勝率和所在的總場(chǎng)數(shù)數(shù)據(jù)獲取過(guò)來(lái)

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

功能沒(méi)啥亮點(diǎn),就是簡(jiǎn)單的實(shí)現(xiàn)。

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

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

當(dāng)然說(shuō)了,這里就,重點(diǎn)是php怎么去抓取數(shù)據(jù)的。

這里要介紹一款非常好的php類(lèi),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ù)抓取類(lèi)

$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);

//獲取排位類(lèi)型

$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) ;

}

上面這些代碼,暴露了哥英語(yǔ)過(guò)了四級(jí)但還是硬傷的bug。

上面這個(gè)類(lèi)很簡(jiǎn)單,難點(diǎn)在于怎么去分析多玩查詢(xún)頁(yè)面的數(shù)據(jù)。用firebug看看吧。

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

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