@KolenBG

Не парсит дальше 3й страницы как исправить ???

def get_page_count(html):
    soup = BeautifulSoup(html, 'lxml')
    pagination = soup.find_all('li', class_='pagination__button')
    if pagination:
        return int(pagination[-1].get_text())
    else:
        return 1


def get_content(html):
    soup = BeautifulSoup(html, 'lxml')
    items = soup.select('div.offer.js-assortment-unit-show')

    tabl = []
    for item in items:
        price_sail = item.find_all('div', class_='offer__price-block')[1]
        if price_sail:
            price_sail = item.find_all_next('div', class_='offer__price-current')
        else:
            price_sail = item.find('div', class_='offer__price-unavailable').get_text(strip=True)

        price_full = item.find_all('div', {'class': 'offer__price-block'})[0]
        if price_full:
            price_full = item.find('div', class_='offer__price-current').get_text(strip=True)
        elif price_full:
            price_full = item.find('div', class_='offer__price-unavailable').get_text(strip=True)
        else:
            price_full = item.find('div', class_='offer__historycal-date').get_text(strip=True)

        print(price_sail) # проверка ЦЕНЫ

        tabl.append({
            'title': item.find('div', class_='offer__title link__text').get_text(strip=True),
            'content': item.find(class_='offer__description').get_text(strip=True),
            'price_full': price_full,
            'price_sale': price_sail,
        })

    return tabl


price_sail = item.find_all('div', class_='offer__price-block')[1]
IndexError: list index out of range


Вот такое сообщение выдает при переходе на 3ю страницу убираю индекс именно в этой строке ошибки нет но тогда парсинг лупит по первому классу, как быть или может где я ошибаюсь
  • Вопрос задан
  • 105 просмотров
Пригласить эксперта
Ответы на вопрос 1
phaggi
@phaggi Куратор тега Python
лужу, паяю, ЭВМы починяю
Не парсит дальше 3й страницы ???

Да, не парсит дальше 3й страницы.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы