import scrapy import pandas as pd import os class KentekSpider(scrapy.Spider): name =…
- User
import scrapy import pandas as pd import os
class KentekSpider(scrapy.Spider): name = 'kentek' start_urls = ['https://kentek.ru/catalog/']
def parse(self, response): self.logger.info('Parsing main catalog page') # Получаем ссылки на главные категории main_categories = response.css( 'div.product--list a::attr(href)').getall() self.logger.info(f'Found main categories: {main_categories}') for main_category in main_categories: yield response.follow(main_category, callback=self.parse_subcategories) def parse_subcategories(self, response): self.logger.info('Parsing subcategories page') # Получаем ссылки на подкатегории subcategories = response.css('div.blocks a::attr(href)').getall() self.logger.info(f'Found subcategories: {subcategories}') for subcategory in subcategories: yield response.follow(subcategory, callback=self.parse_products) def parse_products(self, response): self.logger.info('Parsing products page') # Собираем данные о продуктах и ссылки на страницы продуктов products = response.css('div.product-item a::attr(href)').getall() self.logger.info(f'Found products: {products}') for product_link in products: yield response.follow(product_link, callback=self.parse_product_details) # Обработка пагинации next_page = response.css('a.next::attr(href)').get() if next_page is not None: yield response.follow(next_page, callback=self.parse_products) def parse_product_details(self, response): self.logger.info('Parsing product details page') # Получаем данные о товаре и аналогах category_name = response.css( 'ul.breadcrumb li a span::text').getall()[-1] subcategory_name = response.css( 'ul.breadcrumb li a span::text').getall()[-2] product_data = { 'Название категории': category_name, 'Подкатегория': subcategory_name, 'Название товара': response.css('h1.npc__name::text').get(), 'Бренд': response.css('.npc__value a::text').get(), 'Артикул': response.css('span.npc__key + span::text').get(), 'Цена': response.css('div.npc__price::text').get(), } # Сбор аналогов товаров analogs = response.css('tr.result-table__row') analog_data = [] prices = [] for analog in analogs: analog_info = { 'Название товара': analog.css('.result-table__info-description::text').get(), 'Бренд товара': analog.css('.result-table__info-brand span::text').get(), 'Цена': analog.css('.result-table__part-cell.price::text').get(), } price = analog.css('.result-table__part-cell.price::text').get() if price: price = price.replace(' ₽', '').replace( ' ', '').replace(',', '.') prices.append(float(price)) analog_data.append(analog_info) # Сортировка цен от минимума к максимуму prices.sort() if prices: product_data['Цена'] = f"от {prices[0]} ₽ до {prices[-1]} ₽" # Сохранение данных в Excel self.save_to_excel(category_name, product_data, analog_data) import os - Assistant
Based on the log output and the code provided, it seems that the issue lies within the selectors you are using, which are returning empty results (). Here are a few steps you can take to troubleshoot and resolve the issue: