How to find HTML elements by multiple tags with BeautifulSoup?

BeautifulSoup also supports selecting  elements by multiple tags. To achieve that, we use the function find_all, and we send a list of tags we want to extract.

For example, to extract and elements, we send the tags as a list like this:

from bs4 import BeautifulSoup

html_content = '''

Paragraph

Span Bold ''' soup = BeautifulSoup(html_content, 'html.parser') headers_and_bold_text = soup.find_all(["h1", "b"]) for element in headers_and_bold_text: print(element) # Output: # # Bold

Related BeautifulSoup web scraping questions:

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *