jeudi 19 novembre 2020

Python IF ELSE statement is not working with Beautiful Soup [closed]

For some reason my IF...ELSE statement isn't working in Python. Below is my code:

fav_vid_uploader = soup2.findAll('span',{'class':'name'})[1:]
if fav_vid_uploader:
    for i in fav_vid_uploader:
        print(i.text)
else:
    print('not')

What the code is supposed to do is check if the fav_vid_uploader exists. If it does, it's supposed to print the text, else print that it does not exist.

This is a sample of what I want my output to look like:

Alyssa
Bob
not 
Cassie
not
Dave

But this is what I'm getting instead:

 Alyssa
 Bob
 Cassie
 Dave

How can I fix this? Thank you.

Aucun commentaire:

Enregistrer un commentaire