M
M
Magic Code2020-08-19 23:51:03
Python
Magic Code, 2020-08-19 23:51:03

Why does it say: 'NoneType' object has no attribute 'get_text'?

Good evening!

Here is the code:

for link in soup.find_all(
            'div', class_=['sg-col-4-of-12 sg-col-8-of-16 sg-col-16-of-24'
                           ' sg-col-12-of-20 sg-col-24-of-32 sg-col sg-col-28-of-36 sg-col-20-of-28',
                           'a-section aok-relative s-image-fixed-height'],
    ):
        pprint.pp(link)
        # ссылка на фото
        src = link.find('img', class_='s-image').get('src')
        # название
        alt = link.find('img', class_='s-image').get('alt')
        # rating
        rank = link.find('div', class_='a-row a-size-small').get_text(strip=True)

When I write only one class, I get no errors, but if I add a second one, an error appears!
I'm probably not referring to the 2nd class correctly:
rank = link.find('div', class_='a-row a-size-small').get_text(strip=True)

How to fix?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2020-08-20
@Panda_Code

link.find('div', class_=['класс1','класс2'])

S
soremix, 2020-08-20
@SoreMix

Is there a class on the page at all? Link to the studio

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question