Home > Backend Development > PHP Tutorial > Teach you how to use php to achieve remote acquisition of LOL data_PHP tutorial

Teach you how to use php to achieve remote acquisition of LOL data_PHP tutorial

WBOY
Release: 2016-07-13 10:28:38
Original
905 people have browsed it

The website will be online in a few days.

Recently completed a small function, which is LOL data acquisition,

For example: I give you a number, have you ranked this number? What is the combat effectiveness? Get the winning rate and total number of games data

The data can be checked on Duowan’s website, so the function that needs to be done is remote capture.

Teach you how to use php to achieve remote acquisition of LOL data_PHP tutorial

The function has no highlights, it is just a simple implementation.

Anyway, JS cannot cross domains, and then use PHP to cross domains. It doesn’t matter if you use file_get_content or curl. It is important to understand the business process.

Teach you how to use php to achieve remote acquisition of LOL data_PHP tutorial

The picture above is the execution business flow chart. Once the process is clear, the code will be easy to write

Of course, here, the focus is on how PHP captures data.

Here we would like to introduce a very good PHP class, Simple_html_dom (get the document from Baidu)

Copy code The code is as follows:

public function getData(){
$server = isset($_POST[' gameserver'])?trim($_POST['gameserver']):NULL;
$name = isset($_POST['gamename'])?trim($_POST['gamename']):NULL;
import("@.ORG.SimpleHtmlDom"); //Data capture class
$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);
                                                                                              = $ tempArr[12];
$pwsl = $tempArr[14];
if($pwtype == "5v5 single and double row")
{
$result['pw'] = $pwtotal ; $ Result ['pwsl'] = $ pwsl;
} else {
$ result ['pw'] = "0";
$ result ['pwsl'] = "0" ;
}

$this->ajaxReturn($result) ;
}

The above code exposes the bug that my English has passed CET-4 but is still flawed.
The above class is very simple. The difficulty lies in how to analyze the data on the Duowan query page. Let’s take a look with firebug.
Write more and you will understand. Of course, if you want to check the rank hidden score, you can do it, but you have to go to Ma Huateng’s website to get the data. I won’t explain it in detail here, just provide an idea

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781410.htmlTechArticleThe website will be online in a few days. Recently, a small function has been completed, which is LOL data acquisition. For example: I give you a number, have you ranked this number? What is the combat effectiveness? Win...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template