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