Python BeautifulSoup give multiple tags to findAll
Use regular expressions:
import re
get_tags = soup.findAll(re.compile(r'(hr|strong)'))
The expression r'(hr|strong)'
will find either hr
tags or strong
tags.
You could pass a list, to find any of the given tags:
tags = soup.find_all(['hr', 'strong'])
To find multiple tags, you can use the ,
CSS selector, where you can specify multiple tags separated by a comma ,
.
To use a CSS selector, use the .select_one()
method instead of .find()
, or .select()
instead of .find_all()
.
For example, to select all <hr>
and strong
tags, separate the tags with a ,
:
tags = soup.select('hr, strong')