Ошибка парсинга BeautifulSoup

import requests
def parse():
    URL = 'https://www.olx.ua/elektronika/kompyutery-i-komplektuyuschie/'
    Headers = {
        "User-Agent":
        ""}
    response = requests.get(URL,headers = Headers)
    soup = BeautifulSoup(response.content,'html.parser')
    items = soup.find_all('div',class_="offer-wrapper")
    comps = []
    for item in items:
        comps.append({
            'title': item.find('a',class_='marginright5 link linkWithHash detailsLink').get_text
            })
    for comp in comps:
        print(comp)

parse()

Ответы (1 шт):

Автор решения: CrazyElf

Не всегда находится нужный класс. Нужно проверять, нашёлся или нет:

    for item in items:
        found = item.find('a',class_='marginright5 link linkWithHash detailsLink linkWithHashPromoted')
        if found:
            comps.append({
                'title': found.get_text()
                })
→ Ссылка