How can I strip comment tags from HTML using BeautifulSoup?

后端 未结 4 788
暖寄归人
暖寄归人 2020-11-28 13:41

I have been playing with BeautifulSoup, which is great. My end goal is to try and just get the text from a page. I am just trying to get the text from the body, with a speci

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 14:07

    if mutation isn't your bag, you can

    [t for t in soup.find_all(text=True) if not isinstance(t, Comment)]
    

提交回复
热议问题