0

Парсер должен собирать цены и выводить в консоль. Выводит только единственную цену. Если использовать метод .getall() вместо .get() в условиях, то показывает все существующие цены.
В чем проблема, что не выводит все цены?

class WildberriesSpider(scrapy.Spider):
    name = 'Wildberries'
    allowed_domains = ['wildberries.ru']
    start_urls = ['https://www.wildberries.ru/catalog/muzhchinam/odezhda/verhnyaya-odezhda']

    def parse(self, response: HtmlResponse):

        for card in response.xpath('//div[@class="dtList i-dtList j-card-item "]'):

            if card.xpath('//ins[@class="lower-price"]/text()') is not None:
                price = card.xpath('..//ins[@class="lower-price"]/text()').get()
            else:
                price = card.xpath('..//span[@class="lower-price"]/text()').get()

            yield {'price': price.replace('\xa0', '')}

1 ответ 1

0
    import scrapy


def clean(text):
    digits = [s for s in text if s.isdigit()]
    clean_text = ''.join(digits)
    if not clean_text:
        return None
    return int(clean_text)

class QuotesSpider(scrapy.Spider):
    name = "Wildberries"
    allowed_domains = ['wildberries.ru']
    start_urls = [
        'https://www.wildberries.ru/catalog/muzhchinam/odezhda/verhnyaya-odezhda',

    ]

    def parse(self, response):
        for quote in response.css('.dtList-inner'):
            link = quote.css('.dtlist-inner-brand-name')
            title1 = link.css('.brand-name::text').get()
            title2 = link.css('.goods-name::text').get()
            title = title1 + '/' + title2
            raw_price = quote.css('.lower-price::text').get()
            price =raw_price and clean(raw_price) or None
            yield {
                'title': title,
                'price': price,
            }

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.