A
A
AlexCruel2020-07-20 10:01:14
Python
AlexCruel, 2020-07-20 10:01:14

How to extract text from a tag using BeautifulSoup?

In 'price' writes 'NoneType' object has no attribute 'text'.

for item in items:
        cards.append(
            {
                'title': item.find('div', class_='h3').find('a').get_text(strip=True),
                <b>'price': item.find('span', class_='g-price-summ-cur').text(strip=True),</b>
                'link_product': item.find('div', class_='h3').find('a').get('href')
            }
        )
    return cards


Tried to remove .text and call here:

for item in items:
            writer.writerow([item['title'], <b>item['price'].text</b>, item['link_product']])

From links, blocks everything works with 'get_text()'.
How and where can I extract text from ? Property, method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Federalt, 2020-07-20
@AlexCruel

prices are requested by a separate request for each product on the page, either through selenium or make an additional request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question