(Apr-16-2021, 01:09 PM)KatMac Wrote: How do I get the value "One" from this class?
One
is part of the attribute name star-rating One
so it's one text.Will find it even if left out
One
in search,can find attribute name using attrs
.>>> from bs4 import BeautifulSoup >>> >>> html = '<p class="star-rating One">' >>> soup = BeautifulSoup(html, 'lxml') >>> find_p = soup.select_one('.star-rating') >>> find_p <p class="star-rating One"></p> >>> find_p.attrs {'class': ['star-rating', 'One']} >>> find_p.attrs.get('class')[1] 'One'