K
K
kirillinyakin2020-05-22 16:41:11
Python
kirillinyakin, 2020-05-22 16:41:11

How to make BS4 look for tags with class1 but not class2?

How to make BS4 not include tags that have a specific class. For example, there is an a tag that has class1 and class2, it is not needed, but there is an a tag that has only class1, which is just needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Tropanets, 2020-05-22
@kirillinyakin

tags = soup.findAll('tag_name',{'class':'class1'})
class1 = []
for tag in tags:
    if tag['class'] == 'class1':
        class1.append(tag)

had the same problem - I think this code will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question