RedRabbit, в твоём случае нет необходимости создавать текстовый файл, т.к. основной код не закодирован. Вместо 1.txt можно указать includes.php
Непонятно, откуда взялся массив $GLOBALS['_1773714188_']. У меня после замены eval на echo он называется $GLOBALS['_367778370_'].
В остальном всё правильно, подставляешь в $replace значение $GLOBALS['_367778370_'] и всё.
Непонятно, откуда взялся массив $GLOBALS['_1773714188_']. У меня после замены eval на echo он называется $GLOBALS['_367778370_'].
В остальном всё правильно, подставляешь в $replace значение $GLOBALS['_367778370_'] и всё.
PHP:
<? class mailparse{var $sleep=0;var $proxy=0;var $key=0;var $noimg=0;var $nodesc=0;var $coldesc=0;public function flush_echo($text){echo $text ."<br />";flush();}public function get_page($url){$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.2");curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);if(!empty($this->proxy)){$proxy_list=file('proxy.txt');curl_setopt($ch,CURLOPT_PROXY,trim($proxy_list[rand(0,count($proxy_list)-1)]));}curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);curl_setopt($ch,CURLOPT_HEADER,0);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);$page=curl_exec($ch);if(!empty($this->sleep)){sleep($this->sleep);}if(file_exists('stop.txt'))die('<b>Парсинг прерван по запросу пользователя.</b>');if(substr_count($page,"<td class=\"headCode\">403</td>")){die("<b>Вы забанены Яндекс Маркетом</b>");}return($page);}public function parse_list($url,$number){$num=0;$page=$this->get_page($url);preg_match("/<div class=\"t75 mb30\">Найдено\: <b><span id=\"total_cnt\">(.*?)<\/span><\/b><\/div>/",$page,$col);$col=explode(" ",$col[1]);$col=$col[0];$pages=ceil($col/15);if(empty($pages)){$num=0;preg_match("/<h1 class=mb10>(.*?)<\/h1>/",$page,$cat_name);$query=mysql_query("SELECT * FROM category WHERE cat_name='" .trim($cat_name[1]) ."'");if(mysql_numrows($query)){$this->flush_echo("<b>Пишем в категорию " .trim($cat_name[1]) ."</b>");$data=mysql_fetch_array($query);$cid=$data['id'];}else{$this->flush_echo("<b>Создана категория " .trim($cat_name[1]) ."</b>");mysql_query("INSERT INTO category VALUES('','" .trim($cat_name[1]) ."')");$cid=mysql_insert_id();}$page=str_replace("\r","",$page);$page=str_replace("\n","",$page);$page=str_replace("\t","",$page);preg_match("/<div class=\"t75 mb7\">Найдено \: <b>товаров (.*?)<\/b><\/div>/",$page,$col);$col=explode(" ",$col[1]);$col=$col[0];$pages=ceil($col/15);for($i=1;$i<$pages+1;$i++){if(!substr_count($url,"?")){$page=$this->get_page($url ."?page=$i");}else{$page=$this->get_page($url ."&page=$i");}$page=str_replace("\r","",$page);$page=str_replace("\n","",$page);$page=str_replace("\t","",$page);preg_match_all("/<h2 style=\"font-size\: 100\%\; margin-bottom: 3px\"><a name=\"g37\" target=\"\_blank\" href=\"\/go\/\?(.*?)\">(.*?)<\/a><\/h2>/",$page,$names);preg_match_all("/<div class=\"copy ofh\" style=\"height: 42px\; font-size: 75\%\">(.*?)<\/div>/",$page,$desc);preg_match_all("/Цена: (.*?) руб\./",$page,$price2);preg_match_all("/<img src=\"http:\/\/img\.torg\.mail\.ru\/sell_new\/(.*?)\"/",$page,$imgs);foreach($names[2]as $id=>$name){$name=trim($name);$price=strip_tags($price2[1][$id]);$price=trim($price);$price=str_replace(" ","",$price);if(empty($price)){$price=rand(1000,10000);}$description=strip_tags(trim($desc[1][$id]));$query=mysql_query("SELECT * FROM product WHERE name='$name'");if(!empty($number)&& $num>=$number){die("<b>Парсинг завершен.</b>");}if(!mysql_numrows($query)){if(!empty($imgs[1][$id])){$img=file_get_contents("http://img.torg.mail.ru/sell_new/" .$imgs[1][$id]);$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name",$img);}if(!empty($file_name)|| empty($this->noimg)){if(!empty($description)&& $description!="Описание отсутствует"){if(empty($this->coldesc)|| strlen($description)>$this->coldesc){if(!empty($this->key)){$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
$sname=strtolower($items[2][$id]);if(substr_count($sname,$this->key)){mysql_query("INSERT INTO product VALUES('','$cid','$name','$file_name','$price','','0','')");$pid=mysql_insert_id();mysql_query("INSERT INTO hars VALUES ('','Описание','$cid')");$hid=mysql_insert_id();mysql_query("INSERT INTO hars_values VALUES('$hid','$pid','" .$description ."')");$this->flush_echo("<font color='green'>$name</font>");$num++;}else{$this->flush_echo("<font color='green'>В записи \"" .trim($items[2][$id]) ."\"</font> <b>нет ключевого слова</b>");flush();}}else{if(!empty($number)&& $num>=$number){die("<b>Парсинг завершен.</b>");}$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
mysql_query("INSERT INTO product VALUES('','$cid','$name','$file_name','$price','','0','')");$pid=mysql_insert_id();mysql_query("INSERT INTO hars VALUES ('','Описание','$cid')");$hid=mysql_insert_id();mysql_query("INSERT INTO hars_values VALUES('$hid','$pid','" .$description ."')");$this->flush_echo("<font color='green'>$name</font>");$num++;}}else{$this->flush_echo("<font color='green'>У товара \"$name\"</font> <b>слишком короткое описание</b></font>");}}else{$this->flush_echo("<font color='green'>У товара \"$name\"</font> <b>нет описания</b></font>");}}else{$this->flush_echo("<font color='green'>У товара \"$name\"</font> <b>нет фото</b></font>");}}else{$this->flush_echo("<font color='green'>Запись \"$name\"</font> <b>уже есть в базе</b></font>");}}}}else{$this->flush_echo("<b>В категории найдено $col записей ($pages страниц)</b>");flush();preg_match("/<h3 class=\"mb10\">(.*?)<\/h3>/",$page,$cat_name);$query=mysql_query("SELECT * FROM category WHERE cat_name='" .trim($cat_name[1]) ."'");if(mysql_numrows($query)){$this->flush_echo("<b>Пишем в категорию " .trim($cat_name[1]) ."</b>");$data=mysql_fetch_array($query);$cid=$data['id'];}else{$this->flush_echo("<b>Создана категория " .trim($cat_name[1]) ."</b>");mysql_query("INSERT INTO category VALUES('','" .trim($cat_name[1]) ."')");$cid=mysql_insert_id();}for($i=1;$i<$pages+1;$i++){$page=$this->get_page($url ."&p3[page]=$i");preg_match_all("/<td class=\"ng_info\"><div class=\"box1\" >\n <h1><a href=\"(.*?)\">(.*?)<\/a>/",$page,$items);$this->flush_echo("<br /><b>Открыта страница $i</b>");flush();foreach($items[1]as $id=>$url2){$query=mysql_query("SELECT * FROM product WHERE url='http://torg.mail.ru" .$url2 ."?tab_id=1'");if(!mysql_numrows($query)){if(!empty($number)&& $num>=$number){die("<b>Парсинг завершен.</b>");}if(!empty($this->key)){$sname=strtolower($items[2][$id]);if(substr_count($sname,$this->key)){$this->parse_item("http://torg.mail.ru" .$url2 ."?tab_id=1",$items[2][$id],$cid);$num++;}else{$this->flush_echo("<font color='green'>В записи \"" .trim($items[2][$id]) ."\"</font> <b>нет ключевого слова</b>");flush();}}else{$this->parse_item("http://torg.mail.ru" .$url2 ."?tab_id=1",$items[2][$id],$cid);$num++;}}else{$this->flush_echo("<font color='green'>Запись \"" .trim($items[2][$id]) ."\"</font> <b>уже есть в базе</b></font>");flush();}}}}}public function parse_item($url,$name,$cid){$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
$p_name=explode(" ",$name);if(empty($p_name[1])){$brand="";}else{$brand=$p_name[0];}$page=$this->get_page($url);$page2=str_replace("\r","",$page);$page2=str_replace("\n","",$page2);$page2=str_replace("\t","",$page2);preg_match("/<i><b>(.*?)<\/b> руб.<\/i>/",$page,$price);if(empty($price[1])){preg_match("/<i>от <b>(.*?)<\/b> до <b>(.*?)<\/b> руб\.<\/i>/",$page,$price2);$price2[1]=str_replace(" ","",$price2[1]);$price2[2]=str_replace(" ","",$price2[2]);$price=rand($price2[1],$price2[2]);}else{$price=$price[1];}preg_match_all("/<td nowrap class=par>(.*?)<\/td>/",$page2,$par_names);preg_match_all("/<td class=\"rgt tah t70\"><i>(.*?)<\/i><\/td>/",$page2,$par_values);foreach($par_names[1]as $id=>$par_name){$par_values[1][$id]=str_replace(" "," ",$par_values[1][$id]);if($par_names[1][0]=="Цена"){if(!empty($par_values[1][$id-1])&& $par_values[1][$id-1]!="--"){$pars[$par_name]=$par_values[1][$id-1];}}else{if(!empty($par_values[1][$id])&& $par_values[1][$id]!="--"){$pars[$par_name]=$par_values[1][$id];}}}preg_match_all("/<td class=fst>(.*?)(\ \;<a href=\"\" onclick=\"return (.*?)\">\(\?\)<\/a><div id=\"(.*?)\" class=\"off\"><\/div><\/td>|<\/td>)<td>(.*?)<\/td>/",$page2,$hars);foreach($hars[1]as $id=>$har_name){$hars[5][$id]=str_replace(" "," ",$hars[5][$id]);$pars[$har_name]=$hars[5][$id];}preg_match("/src=\"http:\/\/img\.torg\.mail\.ru\/(.*?)\" \/><\/a>/",$page,$img);if(!empty($img[1])){$img=str_replace("1-1","1-2",$img[1]);$img=file_get_contents("http://img.torg.mail.ru/" .$img);$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name",$img);}else{$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name","");}if(!empty($file_name)|| empty($this->noimg)){if(!empty($pars)){mysql_query("INSERT INTO product VALUES('','$cid','$name','$file_name','$price','','','$url')");$pid=mysql_insert_id();foreach($pars as $par_name=>$par_value){$q=mysql_query("SELECT * FROM hars WHERE name='$par_name' AND cat_id='$cid'");if(!mysql_numrows($q)){mysql_query("INSERT INTO hars VALUES('','$par_name','$cid')");$hid=mysql_insert_id();}else{$d=mysql_fetch_array($q);$hid=$d['id'];}mysql_query("INSERT INTO hars_values VALUES('$hid','$pid','$par_value')");}$this->flush_echo("<font color='green'>$name</font>");}else{$this->flush_echo("<b>Нет описания для $name</b>");}}else{$this->flush_echo("<font color='green'>У товара $name</font> <b>нет фото</b>");}flush();}}class ozonparse extends mailparse{function parse_list($url,$number){$num=0;$page=$this->get_page($url);$page2=str_replace("\r","",$page);$page2=str_replace("\n","",$page2);$page2=str_replace("\t","",$page2);preg_match("/из <b style=\"color\: #000000\;\">(.*?)<\/b><\/small>/",$page2,$col);$pages=ceil($col[1]/20);preg_match("/<h1 class=\"skin_text\">(.*?)<\/h1>/",$page2,$cat_name);$query=mysql_query("SELECT * FROM category WHERE cat_name='" .trim($cat_name[1]) ."'");if(mysql_numrows($query)){$this->flush_echo("<b>Пишем в категорию " .trim($cat_name[1]) ."</b>");$data=mysql_fetch_array($query);$cid=$data['id'];}else{$this->flush_echo("<b>Создана категория " .trim($cat_name[1]) ."</b>");mysql_query("INSERT INTO category VALUES('','" .trim($cat_name[1]) ."')");$cid=mysql_insert_id();}$this->flush_echo("<b>В категории " .$col[1] ." записей ($pages страниц)</b>");for($i=0;$i<$pages;$i++){$page=$this->get_page($url ."?page=$i");$this->flush_echo("<b>Открыта страница $i</b>");$page2=str_replace("\r","",$page);$page2=str_replace("\n","",$page2);$page2=str_replace("\t","",$page2);preg_match_all("/<a href=\"\/context\/detail\/id\/(.*?)\/\" title=\"(.*?)\" onclick=\"setCookieForOmniture\(\'(.*?)\'\, \'catalog_(.*?)-(.*?)\'\)\">(.*?)<\/a>/",$page,$items);foreach($items[1]as $id=>$url2){$query=mysql_query("SELECT * FROM product WHERE url='http://www.ozon.ru/context/detail/id/$url2/'");if(!mysql_numrows($query)){if(!empty($number)&& $num>=$number){die("<b>Парсинг завершен.</b>");}if(!empty($this->key)){$sname=strtolower($items[6][$id]);if(substr_count($sname,$this->key)){$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
$this->parse_item("http://www.ozon.ru/context/detail/id/$url2/",$items[6][$id],$cid);$num++;}else{$this->flush_echo("<font color='green'>В записи \"" .trim($items[6][$id]) ."\"</font> <b>нет ключевого слова</b>");flush();}}else{$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
$this->parse_item("http://www.ozon.ru/context/detail/id/$url2/",$items[6][$id],$cid);$num++;}}else{$this->flush_echo("<font color='green'>Запись \"" .trim($items[6][$id]) ."\"</font> <b>уже есть в базе</b>");flush();}}}}function parse_item($url,$name,$cid){$page=$this->get_page($url);$page2=str_replace("\r","",$page);$page2=str_replace("\n","",$page2);$page2=str_replace("\t","",$page2);$page2=str_replace(" ","",$page2);$page2=str_replace("<li> <b>","<li><b>",$page2);$page=str_replace("<li> <b>","<li><b>",$page);preg_match("/title=\"Производитель\">(.*?)<\/a>/",$page2,$brand);preg_match("/<h1>(.*?)<\/h1>/",$page2,$name);preg_match("/<big class=\"saleblock_price\">(.*?)<\/big>/",$page2,$price);preg_match("/<td colspan=\"2\" class=\"detail\_centralcell vertpadd\"><a href=\"\#images\" onclick=\"return swapPhotos\(document\.(.*?)\_(.*?)\,\'\/multimedia\/(.*?)\/small\/(.*?)\'\,/",$page2,$img);$img[4]=str_replace(".gif",".jpg",$img[4]);$imgu="http://www.ozon.ru/multimedia/" .$img[3] ."/" .$img[4] ."";if(!empty($img[3])){$img=file_get_contents($imgu);$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name",$img);}else{preg_match("/src=\"\/multimedia\/(.*?)\/(.*?)\"/",$page2,$img);$imgu="http://www.ozon.ru/multimedia/" .$img[1] ."/" .$img[2] ."";if(!empty($img[2])){$img=file_get_contents($imgu);$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name",$img);}else{$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name","");}}preg_match_all("/<li><b>(.*?)<\/b>(.*?)\n/",$page,$h);if(!empty($h[1])){foreach($h[1]as $id=>$har_name){if($har_name=="От производителя"){$har_name="Описание";}if($har_name=="От OZON.ru"){$har_name="Характеристики";}$hars[$har_name]=$h[2][$id];}}preg_match_all("/<td class=\"detail_leftpadd vertpadd\" colspan=\"2\"><b>(.*?)<\/b><\/td>/",$page2,$hars_names);preg_match_all("/<td class=\"detail_centralcell vertpadd\">(.*?)<\/td>/",$page2,$hars_values);foreach($hars_names[1]as $id=>$har_name){if($har_name=="От производителя"){$har_name="Описание";}if($har_name=="От OZON.ru"){$har_name="Характеристики";}$hars[$har_name]=strip_tags($hars_values[1][$id],"<br>,<ul>,<li>");}preg_match_all("/<td class=\"vertpadd\" style=\"padding-right: 5px; border: 0px solid \#E8E8E8; border-bottom-width: 1px;\"><b>(.*?)<\/b><\/td>/",$page2,$opts_names);preg_match_all("/<td class=\"vertpadd\" style=\"border: 0px solid #E8E8E8; border-bottom-width: 1px;\">(.*?)<\/td>/",$page2,$opts_values);foreach($opts_names[1]as $id=>$har_name){if($har_name=="От производителя"){$har_name="Описание";}if($har_name=="От OZON.ru"){$har_name="Характеристики";}$hars[$har_name]=strip_tags($opts_values[1][$id],"<br>,<ul>,<li>");}$pars=$hars;if(!empty($pars)){if(!empty($file_name)|| empty($this->noimg)){mysql_query("INSERT INTO product VALUES('','$cid','" .$name[1] ."','$file_name','" .$price[1] ."','" .$brand[1] ."','','$url')");$pid=mysql_insert_id();foreach($pars as $par_name=>$par_value){$q=mysql_query("SELECT * FROM hars WHERE name='$par_name' AND cat_id='$cid'");if(!mysql_numrows($q)){mysql_query("INSERT INTO hars VALUES('','$par_name','$cid')");$hid=mysql_insert_id();}else{$d=mysql_fetch_array($q);$hid=$d['id'];}mysql_query("INSERT INTO hars_values VALUES('$hid','$pid','$par_value')");}$this->flush_echo("<font color='green'>" .$name[1] ."</font>");}else{$this->flush_echo("<font color='green'>У товара " .$name[1] ."</font> <b>нет фото</b>");}}else{$this->flush_echo("<b>Нет описания для " .$name[1] ."</b>");}}}class yamparse extends mailparse{public function parse_ext($url,$number){$page=$this->get_page($url);$page2=substr($page,strrpos($page,"search-stat"));$page2=iconv("utf-8","cp1251",$page2);preg_match("/\—\s(.*?)\.\s<a href=\"\/shop\-info/",$page2,$items_col);$items_col[1]=iconv("utf-8","cp1251",$items_col[1]);$cc=explode(" ",$items_col[1]);$items_col=$cc[0];$pages=ceil($items_col/10);if($pages>100){$pages=100;}$page2=iconv("utf-8","cp1251",$page);preg_match("/<title>(.+)\s–\s/isU",$page2,$cat_name);$query=mysql_query("SELECT * FROM category WHERE cat_name='" .trim($cat_name[1]) ."'");if(mysql_numrows($query)){$this->flush_echo("<b>Пишем в категорию " .trim($cat_name[1]) ."</b>");$data=mysql_fetch_array($query);$cid=$data['id'];}else{$this->flush_echo("<b>Создана категория " .trim($cat_name[1]) ."</b>");mysql_query("INSERT INTO category VALUES('','" .trim($cat_name[1]) ."')");$cid=mysql_insert_id();}$num=0;for($i=1;$i<$pages+1;$i++){$p=$this->get_page($url ."&page=$i");$p=str_replace("\n","",$p);$p=str_replace("\r","",$p);preg_match_all("/<div class=\"b-offers\" id=\"(.*?)\">(.*?)<\/div><\/div><\/div>/",$p,$items);foreach($items[2]as $page){$page=iconv("utf-8","cp1251",$page);preg_match("/<h3 class=\"b-offers__title\"><a target=\"_blank\" class=\"b-offers__name shop-link\" href=\"(.*?)\">(.*?)<\/a><\/h3>/",$page,$name);preg_match("/<span class=\"b-prices__num\">(.*?)<\/span>/",$page,$price);preg_match("/<img class=\"b-offers__img\" src=\"(.*?)\" alt=\"\" width=\"(.*?)\" height=\"(.*?)\"><\/a>/",$page,$img);preg_match_all("/<p class=\"b-offers__spec\">(.*?)<\/p>/",$page,$desc);$description="";$name=$name[2];$price[1]=str_replace(" ","",$price[1]);if(!empty($desc[1])){foreach($desc[1]as $d){$description .= $d ."<br />";}}$query=mysql_query("SELECT * FROM product WHERE name='$name'");if(!mysql_numrows($query)){if(!empty($img[1])){$img=file_get_contents($img[1]);$file_name=time() .rand(0,100000000) .".jpg";file_put_contents("images/$file_name",$img);}if(!empty($file_name)|| empty($_GET['noimg'])){if(!empty($description)&&!description!="<br />"){$nnn=strtolower($name);if(empty($_GET['key'])|| substr_count($nnn,$_GET['key'])){if(empty($_GET['coldesc'])|| strlen($description)>$_GET['coldesc']){if(!empty($_GET['num'])&& $_GET['num']<=$num){die("<b>Парсинг завершен</b>");}$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
mysql_query("INSERT INTO product VALUES('','$cat_id','$name','$file_name','" .$price[1] ."','','0','')");$pid=mysql_insert_id();mysql_query("INSERT INTO hars VALUES ('','Описание','$cat_id')");$hid=mysql_insert_id();mysql_query("INSERT INTO hars_values VALUES('$hid','$pid','" .$description ."')");echo"<font color='green'>$name</font><br />";$num++;}else{echo"<font color='green'>У товара \"$name\"</font> <b>слишком короткое описание</b></font><br />";}}else{echo"<font color='green'>Товар \"$name\"</font> <b>не подходит по ключевому слову</b></font><br />";}}else{echo"<font color='green'>У товара \"$name\"</font> <b>нет описания</b></font><br />";}}else{echo"<font color='green'>У товара \"$name\"</font> <b>нет фото</b></font><br />";}}else{echo"<font color='green'>Запись \"$name\"</font> <b>уже есть в базе</b></font><br />";}}flush();}}public function parse_list($url,$number){$page=$this->get_page($url);preg_match("/<span id=\"m\_count1\">(.*?)\s(.*?)<\/span>/",$page,$items_col);$items_col[1]=iconv("utf-8","cp1251",$items_col[1]);$cc=explode(" ",$items_col[1]);$items_col=$cc[0];$pages=ceil($items_col/10);if($pages>100){$pages=100;}$page2=iconv("utf-8","cp1251",$page);preg_match("/<title>(.+)\s–\s/isU",$page2,$cat_name);preg_match("/<a class=\"b-pager__next\" href=\"\/(.*?)\">/",$page,$nurl);$nurl="http://market.yandex.ru/" .$nurl[1];$query=mysql_query("SELECT * FROM category WHERE cat_name='" .trim($cat_name[1]) ."'");if(mysql_numrows($query)){$this->flush_echo("<b>Пишем в категорию " .trim($cat_name[1]) ."</b>");$data=mysql_fetch_array($query);$cid=$data['id'];}else{$this->flush_echo("<b>Создана категория " .trim($cat_name[1]) ."</b>");mysql_query("INSERT INTO category VALUES('','" .trim($cat_name[1]) ."')");$cid=mysql_insert_id();}$num=0;for($i=0;$i<$pages;$i++){$nnurl=str_replace("BPOS=10","BPOS=" .($i*10),$nurl);flush();$page=$this->get_page($nnurl);preg_match_all("/<a id=\"(.*?)\" class=\"b-offers__name\" href=\"\/(.*?)\">(.*?)<\/a><\/h3>/",$page,$items);foreach($items[2]as $id=>$item_url){$item_name=iconv("utf-8","cp1251",$items[3][$id]);$query=mysql_query("SELECT * FROM product WHERE url='http://market.yandex.ru/$item_url'");if(!mysql_numrows($query)){if(!empty($number)&& $num>=$number){die("<b>Парсинг завершен.</b>");}if(!empty($this->key)){$sname=strtolower($item_name);if(substr_count($sname,$this->key)){$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
$this->parse_item("http://market.yandex.ru/$item_url",$item_name,$cid);$num++;}else{$this->flush_echo("<font color='green'>В записи \"" .trim($item_name) ."\"</font> <b>нет ключевого слова</b>");flush();}}else{$pc=mysql_numrows(mysql_query("SELECT * FROM product"));
$this->parse_item("http://market.yandex.ru/$item_url",$item_name,$cid);$num++;}}else{$this->flush_echo("<font color='green'>Запись \"" .trim($item_name) ."\"</font> <b>уже есть в базе</b>");flush();}}$this->flush_echo("<b>Закрываем страницу $i<br /><br /></b>");}}function parse_item($url,$name,$cid){$page=$this->get_page($url);preg_match("/<h1 id=\"global-model-name\" style=\"margin-bottom:0px;\">(.*?)<\/h1>/",$page,$name);preg_match("/<span class=\"b-prices__num\">(.*?)<\/span>/",$page,$price);preg_match_all("/<tr><td class=\"label\"><span>(.*?)<\/span><\/td><td>(.*?)<\/td><\/tr>/",$page,$hars);preg_match("/<title>(.+)\s/iU",$page,$brand);preg_match("/<a href=\"(.*?)\" target=\"_blank\" id=\"(.*?)\">/",$page,$img);$name=iconv("utf-8","cp1251",$name[1]);$price=iconv("utf-8","cp1251",$price[1]);$brand=iconv("utf-8","cp1251",$brand[1]);if(empty($price)){$price=rand(100,10000);}if(!empty($img[1])){$imgf=file_get_contents($img[1]);if(!empty($imgf)){$img=time() .rand(0,99999) .".jpg";file_put_contents("images/" .$img,$imgf);}else{$img="";}}else{$img="";}if(!empty($hars[1])){if(!empty($img)|| empty($this->noimg)){mysql_query("INSERT INTO product VALUES('','$cid','$name','$img','$price','$brand','0','$url')");$pid=mysql_insert_id();foreach($hars[1]as $id=>$har_name){$har_name=iconv("utf-8","cp1251",$har_name);$har_value=iconv("utf-8","cp1251",$hars[2][$id]);$q=mysql_query("SELECT * FROM hars WHERE name='$har_name' AND cat_id='$cid'");if(!mysql_numrows($q)){mysql_query("INSERT INTO hars VALUES('','$har_name','$cid')");$hid=mysql_insert_id();}else{$d=mysql_fetch_array($q);$hid=$d['id'];}mysql_query("INSERT INTO hars_values VALUES('$hid','$pid','$har_value')");}$this->flush_echo("<font color='green'>" .$name ."</font>");}else{$this->flush_echo("<font color='green'>У товара " .$name ."</font> <b>нет фото</b>");}}else{$this->flush_echo("<b>Нет описания для " .$name ."</b>");}}}?>