Skip to content Skip to sidebar Skip to footer

Beautifulsoup Find The Tag And Attribute Of Without Value?

I'm trying to get the content of the particular tag which having the attribute but no values. How can I get it for example cont = '

Solution 1:

You can use attr=True for this case.

cont = '<nav></nav> <nav breadcrumbs> <a href="">aa</a></nav> <nav></nav>'
soup = BeautifulSoup(cont, 'lxml')  # works with 'html.parser' too.
print(soup.find('nav', breadcrumbs=True))
# which is the same as print(soup.find('nav', {'breadcrumbs': True}))

Output:

<navbreadcrumbs=""><ahref="">aa</a></nav>

Post a Comment for "Beautifulsoup Find The Tag And Attribute Of Without Value?"