Python/BeautifulSoup - how to remove all tags from an element?

后端 未结 7 1589
执念已碎
执念已碎 2020-11-28 06:01

How can I simply strip all tags from an element I find in BeautifulSoup?

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 06:48

    Code to simply get the contents as text instead of html:

    'html_text' parameter is the string which you will pass in this function to get the text

    from bs4 import BeautifulSoup
    
    soup = BeautifulSoup(html_text, 'lxml')
    text = soup.get_text()
    print(text)
    

提交回复
热议问题