Beautifulsoup find the tag and attribute of without value?

前端 未结 1 1692
南方客
南方客 2021-01-27 04:34

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 = \' <         


        
1条回答
  •  轮回少年
    2021-01-27 05:06

    You can use attr=True for this case.

    cont = '  '
    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:

    
    

    0 讨论(0)
提交回复
热议问题