Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- include('libz/ganon.php');
- $debug = true;
- if ($debug) echo "Отладка включена ", "<br>\n","===================================", "<br>\n";
- //Get login page
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 1);
- 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");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
- curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/tmp/cookies.txt");
- curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/tmp/cookies.txt");
- curl_setopt($ch, CURLOPT_URL, "http://mwo.smurfy-net.de/login");
- $result = curl_exec($ch);
- $html = str_get_dom($result);
- foreach($html('input[name="_csrf_token"]') as $element) {}
- //Логинимся
- curl_setopt($ch, CURLOPT_URL, "http://mwo.smurfy-net.de/login_check");
- curl_setopt($ch, CURLOPT_POST, 1);
- $fields = array(
- '_username' => 'hellvesper',
- '_password' => 'nthhfbyr',
- '_submit' => 'Login',
- '_csrf_token' => $element->value
- );
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
- curl_exec($ch);
- //Получаем данные залогиненого юзера
- curl_setopt($ch, CURLOPT_POST, 0);
- curl_setopt($ch, CURLOPT_URL, "http://mwo.smurfy-net.de/mechlab/mechbay");
- $result = curl_exec($ch);
- $result = explode("{", $result);
- $result = '{'.$result[1];
- $mechbay = json_decode($result, true); //Декодим JSON и представляем ввиде ассоциативного массива
- $mechbay = $mechbay['content'];
- $html = str_get_dom($mechbay);
- $mech = Array();
- foreach($html('tr') as $tr)
- {
- foreach($tr('td.mechbay-name') as $mechName)
- $mechName = $mechName->getPlainText();
- //foreach ($tr('span.label.label-mech-hardpoint-beam') as $hardpoint)
- // $mech[$mechName]['hardpoint'] = $hardpoint->html();
- foreach($tr('small') as $weapon) {
- $weapon = $weapon->html();
- $weapon = explode(" ", $weapon);
- foreach ($weapon as &$value) {
- $value = strip_tags($value);
- }
- unset($value);
- //print_r($weapon);
- $mech[$mechName]['weapon'] = $weapon;
- }
- foreach($tr('.label-info') as $key => $el) {
- //if($debug) echo $key.' ', $el->getPlainText(), "<br>\n";
- switch ($key) {
- case 0:
- # code...
- $mech[$mechName]['engine']['type'] = $el->getPlainText();
- if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => type: ', $el->getPlainText(), "<br>\n";
- break;
- case 1:
- # code...
- $mech[$mechName]['engine']['baseSpeed'] = $el->getPlainText();
- if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => baseSpeed: ', $el->getPlainText(), "<br>\n";
- break;
- }
- }
- foreach($tr('.label-success') as $key => $el) {
- //if($debug) echo $key.' ', $el->getPlainText(), "<br>\n";
- switch ($key) {
- case 0:
- # code...
- $mech[$mechName]['engine']['hs'] = $el->getPlainText();
- if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => hs: ', $el->getPlainText(), "<br>\n";
- break;
- case 1:
- # code...
- $mech[$mechName]['engine']['skillSpeed'] = $el->getPlainText();
- if($debug) echo $key.' '.'Элемент присвоен ', key($mech),' => engine => skillSpeed: ', $el->getPlainText(), "<br>\n";
- break;
- }
- }
- foreach($tr('td') as $upgrades)
- $mech[$mechName]['upgrades'] = $upgrades->getPlainText();
- if($debug) next($mech);
- }
- print_r($mech);
- die();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bootstrap 101 Template</title>
- <!-- Bootstrap -->
- <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script src="js/bootstrap.min.js"></script>
- </head>
- <body>
- <h1>Parser</h1>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement