From 6d25c0e9e1ff718541be61b4c197dc7e2dd7c813 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Thu, 4 Sep 2025 10:09:14 +0300 Subject: [PATCH] =?utf8?q?=D0=9E=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/MarketplaceController.php | 124 +---------------------- 1 file changed, 1 insertion(+), 123 deletions(-) diff --git a/erp24/commands/MarketplaceController.php b/erp24/commands/MarketplaceController.php index 65b78802..1c337ce1 100644 --- a/erp24/commands/MarketplaceController.php +++ b/erp24/commands/MarketplaceController.php @@ -204,126 +204,4 @@ class MarketplaceController extends Controller } return ExitCode::OK; } - - - public function actionParseFlowwow() - { - { - $this->stdout("Начинаем парсинг Flowwow..." . PHP_EOL); - - // URL для парсинга - $baseUrl = 'https://flowwow.com/shop/baza-cvetov-24f-6167/'; - - $this->stdout("Загружаем основную страницу: {$baseUrl}" . PHP_EOL); - - // Контекст для обхода SSL - $context = stream_context_create([ - "ssl" => [ - "verify_peer" => false, - "verify_peer_name" => false, - ], - "http" => [ - "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", - "timeout" => 30 - ] - ]); - - try { - // Загружаем основную страницу - $dom = HtmlDomParser::file_get_html($baseUrl, false, $context); - - $categoryWrappers = $dom->findMulti('div.category-wrapper') ?? []; - $categoryCount = count($categoryWrappers); - - foreach ($categoryWrappers as $index => $category) { - $categoryNameElement = $category->findOne('h2.category-name'); - $categoryName = $categoryNameElement ? trim((string)$categoryNameElement->text()) : 'Без категории'; - - $productCards = $category->findMulti('div.category-content-item a.product-card') ?? []; - $productCount = count($productCards); - - foreach ($productCards as $productIndex => $card) { - $productPath = $card->getAttribute('href') ?: null; - if (!$productPath) { continue; } - - $productUrl = 'https://flowwow.com' . $productPath; - - $nameElement = $card->findOne('div.name'); - $priceElement = $card->findOne('div.price span'); - $imgElement = $card->findOne('img'); - - $productName = $nameElement ? trim((string)$nameElement->text()) : ''; - $priceText = $priceElement ? trim((string)$priceElement->text()) : ''; - $price = (int)preg_replace('/[^\d]/u', '', $priceText); - $imageUrl = $imgElement ? (string)$imgElement->getAttribute('src') : ''; - - $productData = [ - 'category' => $categoryName, - 'name' => $productName, - 'price' => $price, - 'image_url' => $imageUrl, - 'product_url' => $productUrl - ]; - - try { - $this->stdout("Загружаем страницу товара..." . PHP_EOL); - - // Загружаем страницу товара - $productDom = HtmlDomParser::file_get_html($productUrl, false, $context); - if ($productDom !== false) { - $this->stdout("Страница товара загружена, извлекаем данные..." . PHP_EOL); - - // Извлечение описания - $descriptionElement = $productDom->findOne('div.product-card-content'); - if ($descriptionElement) { - $productData['description'] = trim((string)$descriptionElement->text()); - } - - $properties = []; - foreach ($productDom->findMulti('div.property-item') ?? [] as $item) { - $propName = $item->findOne('div.property-name')?->text(); - $propValue = $item->findOne('div.property-value')?->text(); - if ($propName !== null && $propValue !== null) { - $properties[trim((string)$propName)] = trim((string)$propValue); - } - } - $productData['properties'] = $properties; - - $this->stdout("Характеристики извлечены: " . count($properties) . " свойств" . PHP_EOL); - - // $productDom->close(); - } - } catch (\Exception $e) { - $this->stdout("Ошибка при загрузке страницы товара: " . $e->getMessage() . PHP_EOL); - $productData['error'] = 'Не удалось загрузить страницу товара: ' . $e->getMessage(); - } - - $products[] = $productData; - $this->stdout("Товар добавлен в результат: {$productName}" . PHP_EOL); - - // Задержка между запросами - $delay = 500000; // 0.5 секунды - $this->stdout("Ждем {$delay} микросекунд перед следующим запросом..." . PHP_EOL); - usleep($delay); - } - } - - // $dom->close(); - - $this->stdout("Парсинг завершен. Обработано товаров: " . count($products) . PHP_EOL); - - // Сохраняем результат в файл (опционально) - $filename = date('Y-m-d_H-i-s') . '_flowwow_products.json'; - file_put_contents($filename, json_encode($products, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); - $this->stdout("Результат сохранен в файл: {$filename}" . PHP_EOL); - - return ExitCode::OK; - - } catch (\Exception $e) { - $this->stdout("Произошла ошибка: " . $e->getMessage() . PHP_EOL); - return ExitCode::SOFTWARE; - } - } - } - -} \ No newline at end of file +} -- 2.39.5