function getpokerstaropenplayers() { //http://www.intellipoker.tw/leagues/Open-League/leaderboard?page=1 // 获取扑克之星开放玩家排名 $url = "http://www.intellipoker.tw/leagues/Open-League/leaderboard"; $html = file_get_html($url); if($html == false) { echo "get false"; exit(0); } $playerrow = $html->find('tr[class="odd"]'); $playerdata = array(); if(!file_exists("d://pokerfree/paiming1.txt")) { foreach($playerrow as $row) { $paiming = $row->children[1]; $palyername = $row->children[3]->find("a"); $score = $row->children[count($row->children) - 1]->find("a"); //print_r($paiming->innertext); //print_r($palyername[0]->innertext); //print_r($score[0]->innertext); $name = $palyername[0]->innertext; $name = str_replace("&", "&",$name); $name = str_replace("<", "<",$name); $name = str_replace(">", ">",$name); $name = str_replace("'", "'",$name); $name = str_replace("\"", """,$name); file_put_contents("d://pokerfree/paiming1.txt","<note player=\"".$name."\" label=\"5\" update=\"1404984118\">".$paiming->innertext.",".$score[0]->innertext."</note>\n",FILE_APPEND); //$playerdata[$paiming] = array($paiming,$palyername,$score); } } else { $data = file_get_contents("d://pokerfree/paiming1.txt"); } for($i = 1;$i <= 500;$i++) { if(!file_exists("d://pokerfree/paiming{$i}.txt")) { $url = "http://www.intellipoker.tw/leagues/Open-League/leaderboard?page=".$i; $html = file_get_html($url); if($html == false) { continue; } $playerrow = $html->find('tr[class="odd"]'); foreach($playerrow as $row) { if(count($row->children) < 6) continue; $paiming = $row->children[1]; $palyername = $row->children[3]->find("a"); $score = $row->children[count($row->children) - 1]->find("a"); //print_r($paiming->innertext); //print_r($palyername[0]->innertext); //print_r($score[0]->innertext); //echo "<note player=\"".$palyername[0]->innertext."\" label=\"5\" update=\"1404984118\">".$paiming->innertext.",".$score[0]->innertext."</note>\n"; $name = $palyername[0]->innertext; $name = str_replace("&", "&",$name); $name = str_replace("<", "<",$name); $name = str_replace(">", ">",$name); $name = str_replace("'", "'",$name); $name = str_replace("\"", """,$name); file_put_contents("d://pokerfree/paiming{$i}.txt","<note player=\"".$name."\" label=\"5\" update=\"1404984118\">".$paiming->innertext.",".$score[0]->innertext."</note>\n",FILE_APPEND); } } } //<note player="harry_bt2013" label="5" update="1404984118">会玩NL2-7等大牌ALL IN</note> }
上面代码用到第三方HTML解析库simple_html_dom.php
只是抓取了500页以内的玩家排名
每一页的玩家排名数据都各自生成一个文件
然后通过批命令 copy *.txt > paiming.txt 合并出扑克之星自定义的标注文件
因为通过网页抓取,所以生成XML文件时候需要把一些字符转义
还有涉及到PHP 如何解析出HTML数据用法,值得记录下来。
下面是玩家排名的一行的HTML代码。这样就可以知道PHP要查找到HTML代码.
<tr class="odd"> <td></td> <td>1</td> <td class="marked"> <img src="http://media.intellipoker.com/images_site/global/themes/pso/arrow-dash-000.gif" alt="排名持平"> </td> <td> <img class="b-flag b-flag_DO" src="http://media.intellipoker.com/images_site/global/flags/blank.gif" alt="DO" title="DO"> <a style="color: black;" href="#">Omegit@</a> </td> <td> <img src="/images_system/icons/global-chips20.png"></td> <td class="gap"></td> <td class="marked"> $150 </td> <td class="gap"></td> <td class="marked checked20"> $1,500 </td> <td class="checked" title="participated in:87"><img src="http://media.intellipoker.com/images_site/global/themes/pso/checked.png" alt=""></td> <td> <a style="color: black;" href="/leagues/Open-League/leaderboard?username=Omegit%40&user_id=4296180">2612.10</a> </td> </tr>
这些标注数据可以用来识别网上的那些玩家大概的实力,当然是比不上那种专业数据软件.请见谅