Answers for "beautiful soup get class of a tag"

1

beautiful soup get class name

#finding the class of the first div in soup
soup.div['class']

#finding the class of the first p in soup
soup.p['class']
Posted by: Guest on May-19-2021
0

beautiful soup get specific class

from bs4 import BeautifulSoup

# after storing your HTML text in html_text 
# (lack of fantasy, ok, you got a point)
soup = BeautifulSoup(html_text, "html.parser")

# it will return a list of 'bs4.element.Tag' 
# with class your_class_name
results = soup.find_all(class_ = "your_class_name")
Posted by: Guest on November-11-2021

Code answers related to "beautiful soup get class of a tag"

Python Answers by Framework

Browse Popular Code Answers by Language