Solução convencional
from bs4 import BeautifulSoup, Doctype for item in soup.contents: if isinstance(item, Doctype): item.extract()
Solução listcomp
from bs4 import BeautifulSoup, Doctype [x.extract() for x in soup.contents if isinstance(x, Doctype)]
Comentários