Guest User

Simple php-parser

a guest
Oct 19th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. $username = 'YOUR_LOGIN_HERE';
  2. $password = 'YOUR_PASSWORD_HERE';
  3. $loginUrl = 'https://stat.trifle.net/login';
  4.  
  5. // LOGIN
  6. $ch = curl_init();
  7. curl_setopt($ch, CURLOPT_URL, $loginUrl);
  8. curl_setopt($ch, CURLOPT_POST, 1);
  9. curl_setopt($ch, CURLOPT_POSTFIELDS, 'user='.$username.'&pass='.$password);
  10. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. $store = curl_exec($ch);
  13.  
  14. // GET CONTENT
  15. curl_setopt($ch, CURLOPT_URL, 'https://stat.trifle.net');
  16.  
  17. $content = curl_exec($ch);
  18. curl_close($ch);
  19.  
  20.  
  21. // PARSE
  22. $html = str_get_html($content)
  23. $summary = $html->find('div[class=summary]', 0)
  24.  
  25. $result = '0';
  26. foreach ($summary->find('td[class=odd fon_negative]') as $tds) {
  27.     if(isset($tds)) {
  28.         $bold = $tds->find('b');
  29.         if(isset($bold)) {
  30.             $result = $bold->plaintext;
  31.         }
  32.     }
  33. }
  34.  
  35. // PHP SCRIPT
  36. $status = 'default';
  37.  
  38. if ((intval($result) > -8097) && (intval($result) < 0)) {
  39.     $status = 'good';
  40. }
  41. elseif ((intval($result) < -8097) && (intval($result) > -9299)) {
  42.     $status = 'warning';
  43. }
  44. elseif ((intval($result) < -9299) && (intval($result) > -9900)) {
  45.     $status = 'danger';
  46. }
  47. elseif (intval($result) == 0) {
  48.     $status = 'default';
  49. }
  50.  
  51. $balance = sprintf("<div id='message' class='msg-%s'>%s</div>\n", $status, $result);
Add Comment
Please, Sign In to add comment