Advertisement
Vespertilio

Untitled

Feb 4th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.07 KB | None | 0 0
  1. <?
  2. include('libz/ganon.php');
  3.  
  4. $debug = true;
  5. if ($debug) echo "Отладка включена ", "<br>\n","===================================", "<br>\n";
  6.  
  7. //Get login page
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_HEADER,  1);
  10. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_COOKIEFILE,  dirname(__FILE__)."/tmp/cookies.txt");
  16. curl_setopt($ch, CURLOPT_COOKIEJAR,  dirname(__FILE__)."/tmp/cookies.txt");
  17. curl_setopt($ch, CURLOPT_URL, "http://mwo.smurfy-net.de/login");
  18. $result = curl_exec($ch);
  19.  
  20. $html = str_get_dom($result);
  21. foreach($html('input[name="_csrf_token"]') as $element) {}
  22.  
  23. //Логинимся
  24. curl_setopt($ch, CURLOPT_URL, "http://mwo.smurfy-net.de/login_check");
  25. curl_setopt($ch, CURLOPT_POST, 1);
  26. $fields = array(
  27.     '_username' => 'hellvesper',
  28.     '_password' => 'nthhfbyr',
  29.     '_submit'   => 'Login',
  30.     '_csrf_token' => $element->value
  31. );
  32. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
  33. curl_exec($ch);
  34.  
  35. //Получаем данные залогиненого юзера
  36. curl_setopt($ch, CURLOPT_POST, 0);
  37. curl_setopt($ch, CURLOPT_URL, "http://mwo.smurfy-net.de/mechlab/mechbay");
  38. $result = curl_exec($ch);
  39. $result = explode("{", $result);
  40. $result = '{'.$result[1];
  41.  
  42. $mechbay = json_decode($result, true); //Декодим JSON и представляем ввиде ассоциативного массива
  43. $mechbay = $mechbay['content'];
  44. $html = str_get_dom($mechbay);
  45. $mech = Array();
  46. foreach($html('tr') as $tr)
  47. {
  48.   foreach($tr('td.mechbay-name') as $mechName)
  49.     $mechName = $mechName->getPlainText();
  50.   //foreach ($tr('span.label.label-mech-hardpoint-beam') as $hardpoint)
  51.   //  $mech[$mechName]['hardpoint'] = $hardpoint->html();
  52.   foreach($tr('small') as $weapon) {
  53.     $weapon = $weapon->html();
  54.     $weapon = explode("&nbsp;", $weapon);
  55.     foreach ($weapon as &$value) {
  56.       $value = strip_tags($value);
  57.     }
  58.     unset($value);
  59.     //print_r($weapon);
  60.     $mech[$mechName]['weapon'] = $weapon;
  61.   }
  62.   foreach($tr('.label-info') as $key => $el) {
  63.     //if($debug) echo $key.' ', $el->getPlainText(), "<br>\n";
  64.     switch ($key) {
  65.       case 0:
  66.         # code...
  67.        $mech[$mechName]['engine']['type'] = $el->getPlainText();
  68.         if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => type: ', $el->getPlainText(), "<br>\n";
  69.         break;
  70.       case 1:
  71.         # code...
  72.        $mech[$mechName]['engine']['baseSpeed'] = $el->getPlainText();
  73.         if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => baseSpeed: ', $el->getPlainText(), "<br>\n";
  74.         break;
  75.     }
  76.   }
  77.   foreach($tr('.label-success') as $key => $el) {
  78.     //if($debug) echo $key.' ', $el->getPlainText(), "<br>\n";
  79.     switch ($key) {
  80.       case 0:
  81.         # code...
  82.        $mech[$mechName]['engine']['hs'] = $el->getPlainText();
  83.         if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => hs: ', $el->getPlainText(), "<br>\n";
  84.         break;
  85.       case 1:
  86.         # code...
  87.        $mech[$mechName]['engine']['skillSpeed'] = $el->getPlainText();
  88.         if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => skillSpeed: ', $el->getPlainText(), "<br>\n";
  89.         break;
  90.     }
  91.   }  
  92.   foreach($tr('td') as $upgrades)
  93.     $mech[$mechName]['upgrades'] = $upgrades->getPlainText();
  94.  
  95.   if($debug) next($mech);
  96. }
  97.  
  98. print_r($mech);
  99.  
  100. die();
  101. ?>
  102.  
  103.  
  104.  
  105. <!DOCTYPE html>
  106. <html>
  107.   <head>
  108.     <title>Bootstrap 101 Template</title>
  109.     <!-- Bootstrap -->
  110.     <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
  111.     <script src="http://code.jquery.com/jquery-latest.js"></script>
  112.     <script src="js/bootstrap.min.js"></script>
  113.   </head>
  114.   <body>
  115.     <h1>Parser</h1>
  116.  
  117.   </body>
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement