使用 Beautifulsoup 从 aria-label 获取文本

get text from aria-label using Beautifulsoup

<span class="_1n9k" data-hover="tooltip" tabindex="-1"><a ajaxify="/ufi/reaction/profile/dialog/? ft_ent_identifier=ZmVlZGJhY2s6MzgyODczMjYzMDg5MTQy&amp;reaction_type=1&amp;av=0" aria-label="좋아요 17" class="_1n9l" href="/ufi/reaction/profile/browser/?ft_ent_identifier=ZmVlZGJhY2s6MzgyODczMjYzMDg5MTQy&amp;av=0" rel="dialog" role="button" tabindex="0"><i class="sp_KIvjPBBBAwk sx_eaca68" role="img"></i></a></span>

如何从 'aria-label' 获取文本“좋한요 17”? 我尝试使用 get('aria-label') 但它不起作用

'aria-label'a 标签的 attribute,它位于 span 标签内。以下是提取 attribute:

的值的方法
from bs4 import BeautifulSoup

html = '<span class="_1n9k" data-hover="tooltip" tabindex="-1"><a ajaxify="/ufi/reaction/profile/dialog/? ft_ent_identifier=ZmVlZGJhY2s6MzgyODczMjYzMDg5MTQy&amp;reaction_type=1&amp;av=0" aria-label="좋아요 17" class="_1n9l" href="/ufi/reaction/profile/browser/?ft_ent_identifier=ZmVlZGJhY2s6MzgyODczMjYzMDg5MTQy&amp;av=0" rel="dialog" role="button" tabindex="0"><i class="sp_KIvjPBBBAwk sx_eaca68" role="img"></i></a></span>'

soup = BeautifulSoup(html,'html5lib')

span = soup.find('span', class_ = "_1n9k")

print(span.a['aria-label'])

输出:

좋아요 17