from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'lxml')
from bs4 import Comment
# remove comments
for comment in soup.findAll(text=lambda text:isinstance(text, Comment)):
comment.extract()
# remove angular attributes
for tag in soup.recursiveChildGenerator():
if hasattr(tag, 'attrs'):
tag.attrs = {
key: value
for key, value in tag.attrs.items()
if not key.startswith('ng-')
}
Note: this will only remove the ng-* attributes, and not the ng-* classes.