Teach you how to use PHP to implement the _php instance of LOL data remote acquisition

Source: Internet
Author: User
Tags php class urlencode

The website will be online in a few days.

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

For example: I give you a number, you put this number has been ranked? How much is the battle? Winning and the total number of field data obtained over

The data is on the website that can be searched more, so the function that do is remote crawl.

The function is not what bright spot, is simple realization.

Anyway is JS can not cross domain, and then use PHP to cross the domain, with file_get_content good class or curl good, is not important. Important Yes to understand the business process.

The above diagram is the execution of a business flowchart. Clear the process, and then the code will be good to write

Of course, here, the key is how PHP to crawl data.

Here to introduce a very good PHP class, Simple_html_dom (own Baidu access to documents)

Copy Code code 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 grabbing 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);
}
}
Unset ($tempArray);
Get rank Type
$pwtype = $TEMPARR [8];
$pwtotal = $TEMPARR [12];
$PWSL = $TEMPARR [14];
if ($pwtype = = "5v5 single double Row")
{
$result [' pw '] = $pwtotal;
$result [' pwsl '] = $PWSL;
}else{
$result [' pw '] = "0";
$result [' pwsl '] = "0";
}

$this->ajaxreturn ($result);
}

The above code, exposing the elder brother English after a four-level but still a mishap bug.
The above class is very simple, the difficulty is how to analyze the data of the query page. Take a look at it with Firebug.
If you write more, you'll know. Of course, you want to query rank hidden score, but also can drop, but to go to Ma Teng website to get data, here is not detailed, provide a thought on it

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.