Пример #1
0
 function start()
 {
     $this->tpl->setBlock("breadcrumb", '<a href="/parser">Freelance.ru parser</a>');
     $pQ = new Engine\pQuery();
     $pages = 5;
     $host = "https://freelance.ru";
     $main_url = "https://freelance.ru/projects/";
     $url = "https://freelance.ru/projects/?spec=4";
     $only_pub = true;
     $dom = $pQ->file_get_html($url);
     $pagination = $dom->find("ul.pagination li a");
     $array = [];
     for ($i = 0; $i <= $pages; $i++) {
         $array[] = $main_url . str_replace(".", "", $pagination[$i]->href);
     }
     $dom = null;
     $info_array = [];
     foreach ($array as $url) {
         $array = "";
         $str = file_get_contents($url);
         $str = iconv('cp1251', 'utf-8', $str);
         $dom = $pQ->str_get_html($str);
         $proj_list = $dom->find("div.projects .proj");
         foreach ($proj_list as $value) {
             $type = str_replace("proj ", "", $value->class);
             if ($type == "public" and $only_pub === true or $only_pub === false) {
             } else {
                 continue;
             }
             $array[] = ["id" => str_replace(" ", "", str_replace("/", "", str_replace("projects", "", $value->find("a.descr")[0]->href))), "title" => $value->find("a.ptitle span")[0]->plaintext, "avatr" => $host . $value->find("a.avatr img")[0]->src, "cost" => $value->find("span.cost")[0]->plaintext, "href" => $host . $value->find("a.descr")[0]->href, "date" => $value->find("ul li.pdata")[0]->title, "replies" => $value->find("ul li.messages a i")[0]->plaintext, "descr" => $value->find("a.descr")[0]->plaintext, "type" => $type];
         }
         $dom = null;
         $info_array = array_merge($info_array, $array);
     }
     function isort(&$a, $field, $dir = true)
     {
         $t = call_user_func_array('array_merge_recursive', $a);
         asort($t[$field]);
         $so = array_keys($t[$field]);
         asort($so);
         # исправлено 2012-08-31
         $so = array_keys($so);
         $a = array_combine($so, $a);
         $dir ? ksort($a) : krsort($a);
     }
     isort($info_array, 'date', false);
     $content = "";
     foreach ($info_array as $val) {
         $this->tpl->setAll(['avatr' => $val['avatr'], 'title' => $val['title'], 'cost' => $val['cost'], 'href' => $val['href'], 'date' => $val['date'], 'reply' => $val['replies'], 'descr' => $val['descr']]);
         $content .= $this->tpl->subLoad('parser.tpl');
     }
     $this->tpl->setBlock('content', $content);
 }
Пример #2
0
 function getWeather($cityId)
 {
     $xml = new Engine\pQuery();
     $weather = $xml->file_get_html("http://export.yandex.ru/weather-ng/forecasts/{$cityId}.xml");
     $arr = ["city" => $weather->find('forecast', 0)->city, "country" => $weather->find('forecast', 0)->country];
     foreach ($weather->find('fact') as $value) {
         $arr['current_weather'] = ["station" => $value->find('station[lang=ru]', 0)->plaintext, "temperature" => $value->find('temperature', 0)->plaintext, "weather_type" => $value->find('weather_type', 0)->plaintext, "weather_type_short" => $value->find('weather_type_short', 0)->plaintext, "wind_speed" => $value->find('wind_speed', 0)->plaintext, "wind_direction" => $value->find('wind_direction', 0)->plaintext, "wind_image" => "http://yandex.st/weather/1.2.77/i/wind/" . $value->find('wind_direction', 0)->plaintext . ".gif", "pressure" => $value->find('pressure', 0)->plaintext, "humidity" => $value->find('humidity', 0)->plaintext, "daytime" => $value->find('daytime', 0)->plaintext, "image" => "http://img.yandex.net/i/wiz" . $value->find('image', 0)->plaintext . ".png"];
     }
     foreach ($weather->find('day') as $value) {
         $date = $value->date;
         $arr[$date] = ["sunrise" => $value->find('sunrise', 0)->plaintext, "sunset" => $value->find('sunset', 0)->plaintext];
         foreach ($value->find('day_part') as $daypart) {
             $type = $daypart->type;
             if ($daypart->find('temperature_from', 0) != null) {
                 $arr[$date][$type] = ["temp_from" => $daypart->find('temperature_from', 0)->plaintext, "temp_to" => $daypart->find('temperature_to', 0)->plaintext, "weather_type" => $daypart->find('weather_type', 0)->plaintext, "weather_type_short" => $daypart->find('weather_type_short', 0)->plaintext, "wind_speed" => $daypart->find('wind_speed', 0)->plaintext, "wind_direction" => $daypart->find('wind_direction', 0)->plaintext, "wind_image" => "http://yandex.st/weather/1.2.77/i/wind/" . $daypart->find('wind_direction', 0)->plaintext . ".gif", "pressure" => $daypart->find('pressure', 0)->plaintext, "humidity" => $daypart->find('humidity', 0)->plaintext, "image" => "http://img.yandex.net/i/wiz" . $daypart->find('image', 0)->plaintext . ".png"];
             } else {
                 $arr[$date][$type] = ["temp" => $daypart->find('temperature', 0)->plaintext, "weather_type" => $daypart->find('weather_type', 0)->plaintext, "weather_type_short" => $daypart->find('weather_type_short', 0)->plaintext, "wind_speed" => $daypart->find('wind_speed', 0)->plaintext, "wind_direction" => $daypart->find('wind_direction', 0)->plaintext, "wind_image" => "http://yandex.st/weather/1.2.77/i/wind/" . $daypart->find('wind_direction', 0)->plaintext . ".gif", "pressure" => $daypart->find('pressure', 0)->plaintext, "humidity" => $daypart->find('humidity', 0)->plaintext, "image" => "http://img.yandex.net/i/wiz" . $daypart->find('image', 0)->plaintext . ".png"];
             }
         }
     }
     return $arr;
 }