Last modified: Jan 10, 2023 By Alexander Williams
BeautifulSoup: Get the aria-label attribute
Today, I'm going to show you how to get an aria-label attribute using BeautifulSoup.
Getting the aria-label attribute with example
In the following example, we'll get the aria-label attribute of the span tag.
from bs4 import BeautifulSoup html = ''' <div> <span class="span" aria-label="4 people reacted to this post" role="button"></span> </div> ''' soup = BeautifulSoup(html, 'html.parser') #find Span f = soup.find('span') #Get aria-label attribute of Span print(f['aria-label'])
4 people reacted to this post
Note: You can also get any specific attribute.
In the following example, let's get the role attribute.