Advertisement
tolikpunkoff

getpoll.php

Jul 25th, 2016
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php  
  2.     include 'simple_html_dom.php';
  3.  
  4.     function GetPoll($id)
  5.     {
  6.         $url='http://lj.rossia.org/poll/?id='.$id.'&mode=results';
  7.         //создаём новый объект
  8.         $html = new simple_html_dom();
  9.         //загружаем в него данные
  10.         $html = file_get_html($url);
  11.         if ($html===false) //если что-то не загрузилось
  12.         {
  13.             $answer='ERROR: CONNECTION ERROR ['.$url.']';
  14.             //освобождаем ресурсы
  15.             unset($html);
  16.             return $answer;
  17.         }
  18.         //тут будем парсить
  19.         $ret = $html->find('img[src=/img/dot.gif]'); //нашли приметный gif   
  20.         $answer='';
  21.         foreach ($ret as $img)
  22.         {
  23.             //вытаскиваем родительский элемент
  24.             $parent=$img->parent();
  25.             //вытаскиваем его HTML-код
  26.             $answer=$parent->innertext;
  27.         }
  28.        
  29.         //освобождаем ресурсы
  30.         $html->clear();
  31.         unset($html);
  32.        
  33.         if ($answer=='') $answer='ERROR: GET DATA ERROR ['.$url.']';
  34.        
  35.         return $answer;
  36.     }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement