Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Copyright (c) 2018.
- * Author NightTrolley
- */
- require ('../parser/phpQuery-onefile.php');
- $db_connect = mysqli_connect("localhost", "root", "", "osclass");
- if(!empty($_POST['url'])){
- }
- else{
- echo "Введите url";
- exit();
- }
- if(!empty($_POST['page_count'])) {
- $i = 1;
- $j = $_POST['page_count'];
- for ($i; $i<=$j; $i++){
- $links[] = $_POST['url'] . '&page=' . $i;
- }
- }
- else{
- echo "Введите кол-во страниц";
- exit();
- }
- $replace = array(
- 'Детский мир » ',
- '» Одежда для девочек',
- '» Одежда для мальчиков',
- 'Детская одежда »',
- 'Одежда для новорожденных',
- 'Квартиры, комнаты » ',
- 'Дома » ',
- 'Посуточная аренда жилья » ',
- 'Земля » ',
- '» Audi',
- '» Volkswagen',
- '» Opel',
- 'Транспорт » ',
- '» Saab',
- '» Skoda',
- '» Renault',
- '» Ford',
- '» Nissan',
- '» Peugeot',
- '» Hyundai',
- '» Honda',
- '» BMW',
- '» Chevrolet',
- '» Mazda',
- '» Kia',
- '» ВАЗ',
- 'и аксессуары » Аксессуары для телефонов',
- 'и аксессуары » Мобильные телефоны / смартфоны',
- '» Прочая техника для дома',
- '» Портативная акустика',
- '» Пылесосы',
- 'Электроника » ',
- '» Приставки',
- ' и комплектующие » Настольные компьютеры',
- '» Кофеварки / кофемолки',
- 'Животные »',
- '» Медицина',
- '» Volvo',
- '» Chery',
- '» Daewoo',
- '» Fiat',
- '» Renault',
- '» Mercedes-Benz',
- '» Dacia',
- '» Subaru',
- '» Toyota',
- '» Suzuki',
- 'Все',
- '/ напитки',
- '» Кухонная мебель',
- '» Мебель для гостиной',
- '» Прочие стройматериалы',
- '» Отделочные и облицовочные материалы',
- '» Электроинструмент',
- 'Дом и сад »',
- '» Отопление',
- '» Мебель для спальни',
- '» Кирпич и бетон и пеноблоки',
- '» Бензоинструмент',
- '» Офисная мебель'
- );
- class ImagesHelper {
- public const PATH_TO_FILES = '../dpm/oc-content/uploads/28/';
- public static function generateImagesPath($feth): ?array
- {
- $feth = self::itemResolver();
- $imageThumbNailsPath = [];
- $imagePreviewPath = [];
- foreach(iterator_to_array($feth,true) as $field){
- $thumbNailsPath = sprintf('%s_thumbnail.jpg',$field[0]);
- $previewsPath = sprintf('%s_preview.jpg',$field[0]);
- $imageThumbNailsPath[] = sprintf('%s%s',self::PATH_TO_FILES,$thumbNailsPath);
- $imagePreviewPath[] = sprintf('%s%s',self::PATH_TO_FILES,$previewsPath);
- }
- return [$imageThumbNailsPath,$imagePreviewPath];
- }
- public static function itemResolver(): \Generator
- {
- // $stmt = mysqli_query($db_connect, "select pk_i_id from oc_t_item_resource ORDER by pk_i_id desc");
- // $records = mysqli_fetch_all($stmt);
- $records = [
- 0 => [0 => '4031'],
- 1 => [0 => '4030'],
- 2 => [0 => '4029']
- ];
- foreach($records as $record => $value){
- yield $value;
- }
- }
- }
- function curl_content($url){
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; WinNT; en; rv:1.0.2) Gecko/20030311 Beonex/0.8.2-stable');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,false);
- $html=curl_exec($ch);
- unset($url);
- return $html;
- }
- function category_replace($cat, $replace){
- $slash_replace = str_replace('/', 'и', $cat);
- $replaces = str_replace($replace, '', $slash_replace);
- return trim($replaces);
- }
- /**
- * @param $url
- * @param $id
- * @param $token
- * @return array
- */
- function get_phone_number($url)
- {
- $cookie_path = $_SERVER['DOCUMENT_ROOT'] . '/cookie.dat';
- preg_match('|-ID(.*).html|', $url, $id);
- $olx = curl_init($url);
- curl_setopt($olx, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($olx, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($olx, CURLOPT_HEADER, 1);
- curl_setopt($olx, CURLOPT_COOKIEFILE, $cookie_path);
- curl_setopt($olx, CURLOPT_COOKIEJAR, $cookie_path);
- $result = curl_exec($olx);
- $content = $result;
- curl_close($olx);
- preg_match("|phoneToken = '(.*)';|", $result, $token);
- $olx_number = curl_init('https://www.olx.ua/ajax/misc/contact/phone/' . $id[1] . '/?pt=' . $token[1]);
- curl_setopt($olx_number, CURLOPT_HTTPHEADER, [
- 'Host: www.olx.ua',
- 'Accept: */*',
- 'Accept-Language: uk,ru;q=0.8,en-US;q=0.5,en;q=0.3',
- 'Accept-Encoding: gzip, deflate, br',
- 'Connection: keep-alive',
- 'X-Requested-With: XMLHttpRequest'
- ]);
- curl_setopt($olx_number, CURLOPT_REFERER, $url);
- curl_setopt($olx_number, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
- curl_setopt($olx_number, CURLOPT_COOKIEFILE, $cookie_path);
- curl_setopt($olx_number, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($olx_number, CURLOPT_RETURNTRANSFER, true);
- $result = curl_exec($olx_number);
- curl_close($olx_number);
- unlink( $_SERVER['DOCUMENT_ROOT'].'/cookie.dat');
- $json = json_decode($result);
- return array($content, $json);
- }
- /**
- * @param $db_connect
- * @param $linkimgbd
- */
- function get_img($db_connect, $imgs , $feth){
- var_dump($feth);
- $pk_i_id = $feth[0][0];
- $orig_img_name = $pk_i_id;
- $thumb_img_name = $pk_i_id . '_thumbnail' ;
- $preview_img_name = $pk_i_id . '_preview' ;
- $saveto1 = '../dpm/oc-content/uploads/28/' . $orig_img_name . '.jpg';
- $saveto2 = '../dpm/oc-content/uploads/28/' . $thumb_img_name . '.jpg';
- $saveto3 = '../dpm/oc-content/uploads/28/' . $preview_img_name . '.jpg';
- $ch = curl_init($imgs);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
- $raw = curl_exec($ch);
- curl_close($ch);
- $fp = fopen($saveto1, 'w');
- $fp2 = fopen($saveto2, 'w');
- $fp3 = fopen($saveto3, 'w');
- fwrite($fp, $raw);
- fwrite($fp2, $raw);
- fwrite($fp3, $raw);
- fclose($fp);
- fclose($fp2);
- fclose($fp3);
- }
- /**
- * @param $pricebd
- * @param $titlebd
- * @return string
- */
- function price_replace($pricebd)
- {
- $price_replace = str_replace(" грн.", "", $pricebd);
- $r = str_replace(' ', '', $price_replace) . '000000';
- return $r;
- }
- function country ($db_connect, $location){
- $explode = explode(",", $location);
- $city = trim($explode[0]);
- $reg = trim($explode[1]);
- $region_sql = mysqli_query($db_connect, "select pk_i_id from oc_t_region where s_name = '$reg'");
- $city_sql = mysqli_query($db_connect, "select pk_i_id from oc_t_city where s_name = '$city'");
- $region_res = mysqli_fetch_all($region_sql);
- $city_res = mysqli_fetch_all($city_sql);
- return array($region_res, $city_res, $reg, $city);
- }
- /**
- * @param $db_connect
- * @param $titlebd
- * @param $r
- * @param $namedb
- * @param $contentbd
- * @param $telbd
- * @param $img_name
- */
- function insert_querys($db_connect, $titlebd, $r, $namedb, $contentbd, $telbd, $t, $reg, $c, $reg_name, $city_name)
- {
- $select_query = mysqli_query($db_connect, "select s_title from `oc_t_item_description`");
- $query_res = mysqli_fetch_all($select_query, MYSQLI_ASSOC);
- $time = date('Y-m-d H:i:s');
- if ($query_res !== $titlebd) {
- mysqli_query($db_connect, "insert into `oc_t_item` (fk_i_category_id, dt_pub_date, i_price, fk_c_currency_code, s_contact_name, b_active) values ( '$t', '$time', '$r', 'GRN','$namedb', '1' )");
- $id = mysqli_insert_id($db_connect);
- mysqli_query($db_connect, "insert into `oc_t_item_description` (fk_i_item_id, s_title, s_description) values ($id , '$titlebd', '$contentbd')");
- mysqli_query($db_connect, "insert into `oc_t_item_location` (fk_i_item_id, fk_i_region_id, fk_i_city_id, s_city_area, fk_c_country_code, s_country, s_region, s_city) values ('$id', '$reg', '$c', '$telbd', 'UA', 'Ukraine', '$reg_name', '$city_name')");
- mysqli_query($db_connect, "insert into `oc_t_item_resource` (fk_i_item_id, s_name, s_extension, s_content_type, s_path) values ('$id', 'img', 'jpg', 'image/jpeg', 'oc-content/uploads/28/')");
- $sel = mysqli_query($db_connect, "select pk_i_id from oc_t_item_resource where `fk_i_item_id` = $id");
- $feth = mysqli_fetch_all($sel);
- return $feth;
- }
- }
- foreach ($links as $l) {
- set_time_limit(0);
- $html = curl_content($l);
- phpQuery::newDocument($html);
- $menu = pq('#offers_table')->find('.breakword');
- $prices = pq('.space')->find('a.detailsLink');
- $cat = pq('color-9')->find('.color-9>small')->text();
- foreach ($menu as $res) {
- $pqres = pq($res);
- $linkarray = $pqres->find('a')->attr('href');
- $pricearray = $pqres->find('p.price>strong')->text();
- $title = $pqres->find('a.marginright5>strong')->text();
- $cat = $pqres->find('.color-9>small')->text();
- $url = $linkarray;
- list($content, $json) = get_phone_number($url);
- phpQuery::newDocument($content);
- $htmlcon = pq('#textContent>p')->text();
- $big_img = pq('.photo-glow')->find('img')->attr('src');
- foreach (pq('.tcenter>.photo-glow')->find('img') as $imgs) {
- $imgs = pq($imgs)->attr('src');
- }
- $name = pq('.offer-user__details>h4')->find('a')->text();
- $location = pq('.offer-titlebox__details')->find('.show-map-link')->text();
- phpQuery::newDocument($json->value);
- $tel = pq('span')->text();
- if (empty($tel)) {
- $tel = $json->value;
- }
- $resarray = array(
- 'link' => $linkarray,
- 'price' => $pricearray,
- 'title' => $title,
- 'tel' => $tel,
- 'content' => $htmlcon,
- 'name' => $name,
- );
- $linkbd = $resarray['link'];
- $pricebd = $resarray['price'];
- $titlebd = $resarray['title'];
- $telbd = $resarray['tel'];
- $namedb = $resarray['name'];
- $contentbd = $resarray['content'];
- $r = price_replace($pricebd);
- $rep = category_replace($cat, $replace);
- $sql = mysqli_query($db_connect, "SELECT `fk_i_category_id`, `s_name` FROM `oc_t_category_description` WHERE 1");
- $result = mysqli_fetch_all($sql);
- list($reg_num, $city_num, $reg_name, $city_name) = country($db_connect, $location);
- foreach ($reg_num as $region) {
- foreach ($region as $reg) {
- }
- }
- foreach ($city_num as $city) {
- foreach ($city as $c) {
- }
- }
- foreach ($result as $t) {
- if ($t[1] == $rep) {
- $feth = insert_querys($db_connect, $titlebd, $r, $namedb, $contentbd, $telbd, $t[0], $reg, $c, $reg_name, $city_name);
- [$thumb,$preview] = ImagesHelper::generateImagesPath($feth);
- var_dump($thumb);
- var_dump($preview);
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement