BeautifulSoup4去除HTML文档中的注释

soup = BeautifulSoup(open('index.html'), "html.parser")
comments = soup.findAll(text=lambda text:isinstance(text, Comment))
[comment.extract() for comment in comments]                         
body = soup.body.contents
print(body)

 

 

 

你可能感兴趣的:(Python从搭建到移除)