J
J
JL0LK0BH1K2022-01-16 19:32:11
Python
JL0LK0BH1K, 2022-01-16 19:32:11

Why doesn't find_all work when parsing a site?

def parse():
        url = 'https://www.olx.ua/list/q-'+message.text+'/'
        response = requests.get(url)
        soup = BeautifulSoup(response.text, 'lxml')

        oholoshennja = soup.find_all('div', class_='offer-wrapper')

        data = []

        for posts in oholoshennja:
            post = oholoshennja.find('td', class_='title-cell').find('h3',class_='lheight22').find('a',class_='marginright5').find('strong')
            post_url = oholoshennja.find('td', class_='title-cell').find('h3',class_='lheight22').find('a',class_='marginright5').get('href')
            located = oholoshennja.find('td', class_='bottom-cell').find('div', class_='space').find('p', class_='lheight16').find_all('small', class_='breadcrumb').find_all('span')
            price = oholoshennja.find('p', class_='price').find('strong')


            data.append([post.text, price.text, located.text, post_url])


Error: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
If you use find(), everything works correctly but for one element.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-16
@JL0LK0BH1K

for posts in oholoshennja:
            post = oholoshennja.find(.........

Well, he says correctly - why do a cycle if you don’t use posts, but use the resulting collection? Maybe still post = posts.find()?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question