<? set_time_limit(0); // чтоб успело дограбить всё ignore_user_abort(); // грабить не смотря на ошибки клиента
// Удаляю для начала все содержимое таблиц
if(!mysql_query("DELETE FROM `".BASEPFX."brands`", $db) || !mysql_query("DELETE FROM `".BASEPFX."brands_img`", $db)) { $g_strPageData = $g_strPageData."<b>Не удалось почистить базы</b><br>"; }
// Получаем контент для первой марки
$result = mysql_query("SELECT * FROM `".BASEPFX."words_brands` WHERE `eng` = 'ARMANI'", $db); while($rowMSQL = mysql_fetch_row($result)) { $iPageNum = 1;
for($q = 0; true; ++$q) { $iCurrentPageArea = ($iPageNum / 10) - ($iPageNum % 10 * 0.1);
$strBrandContent = file_get_contents("http://xxxxxxxxxxx.xxxxx/?sub2=".$rowMSQL[1]."&page=$iPageNum¤tpagearea=".$iCurrentPageArea);
$iPids = array(0 => 1000);
// Достаем из него все, что нада // Сначала проверим, не перешли ли мы на несуществующую страницу preg_match_all("/color=red><B>([0-9]{1,4})/m", $strBrandContent, $arrBrandContent);
if($iPageNum > $arrBrandContent[1][0]) { $g_strPageData = $g_strPageData."<font class=\"pData\">Здесь кончили, идем дальше</font><br>"; break; } else { $arrBrandContent = 0;
// Достанем наши PID preg_match_all("/.+pid=([0-9]+)&/m", $strBrandContent, $arrBrandContent);
// Пересобираем т.е. удаляем повторяющиеся for($i = 0; $i < sizeof($arrBrandContent[1]); ++$i) if($arrBrandContent[1][$i] != $arrBrandContent[1][$i-1]) $iPids[$i] = $arrBrandContent[1][$i];
$g_strPageData = $g_strPageData."<font class=\"pData\">Найдено: ".sizeof($iPids)." в ".$rowMSQL[1]." на странице $iPageNum</font><br>";
// Переходим по ссылкам и собираем инфу for($i = 0; $i < sizeof($iPids); ++$i) { $strItemContent = file_get_contents("http://xxxxxx.xxxxx/?pid=".$iPids[$i]); $arrItemContent = 0; $strItem = "";
$strItemContent = trim(trim($strItemContent, "\r\n\t"));
preg_match_all("/([a-zA-Z]20[0-9]{10})/m", $strItemContent, $arrItemContent); $strItem[0] = trim(trim($arrItemContent[1][0], "\r\n\t"));
preg_match_all("/(pbpic.+\.jpg)/m", $strItemContent, $arrItemContent);
// Скачиваем все картинки for($j = 0; $j < sizeof($arrItemContent[1]); ++$j) { $fname = "http://xxxxxx.xxxxx/".$arrItemContent[1][$j];
if(!copy($fname, "data/img_brands/".strtolower(array_pop(explode("/", $fname))))) $g_strPageData = $g_strPageData."<b>Ошибка копирования изображения</b> $fname <br>"; else { $strItem[1] = trim(trim($arrItemContent[1][$j], "\r\n\t")); if(!mysql_query("INSERT INTO `".BASEPFX."brands_img` ( `itemno` , `img` ) VALUES ('".$strItem[0]."', '".strtolower(array_pop(explode("/", $fname)))."');", $db)) { $g_strPageData = $g_strPageData."<font class=\"pRead\"><b>Не могу добавить изображение в базу</b> $fname </font><br>"; } } }
preg_match_all("/Categories.+\\n\s+(.+)\s+<\/TD>/m", $strItemContent, $arrItemContent); $strItem[2] = trim(trim($arrItemContent[1][0], "\r\n\t"));
preg_match_all("/Brands.+\\n\s+(.+)\s+<\/TD>/m", $strItemContent, $arrItemContent); $strItem[3] = trim(trim($arrItemContent[1][0], "\r\n\t"));
preg_match_all("/Gender.+\\n\s+([a-zA-Z]+)\s+<\/TD>/m", $strItemContent, $arrItemContent); $strItem[4] = trim(trim($arrItemContent[1][0], "\r\n\t"));
...............................
preg_match_all("/Size.+\\n\s+(.+)\s+<\/TD>/m", $strItemContent, $arrItemContent); $strItem[5] = trim(trim($arrItemContent[1][0], "\r\n\t"));
if($strItem[5] == "free") $strItem[5] = "Свободный";
if(!empty($strItem[0])) if(!mysql_query("INSERT INTO `".BASEPFX."brands` ( `itemno` , `brand` , `cat` , `gender` , `size` ) VALUES ('".$strItem[0]."', '".$strItem[3]."', '".$strItem[2]."', '".$strItem[4]."', '".$strItem[5]."');", $db)) { $g_strPageData = $g_strPageData."<font class=\"pRead\"><b>Не удалось добавить: ".$strItem[3]." | ".$strItem[2]." | ".$strItem[0]." | ".$strItem[1]." | ".$strItem[4]." | ".$strItem[5]."</b></font><br>"; } else { $g_strPageData = $g_strPageData."Добавлено: ".$strItem[3]." | ".$strItem[2]." | ".$strItem[0]." | ".$strItem[1]." | ".$strItem[4]." | ".$strItem[5]."<br>"; } // После засыпаем на 1-3сек sleep(rand(1, 3)); }
++$iPageNum; sleep(60 + rand(60, 120)); } } } ?> |