for child in soup.contents:
    if isinstance(child, BS.Declaration):
        declaration_type = child.string.split()[0]
if declaration_type.upper() == 'DOCTYPE':
    pass
Get document DOCTYPE with BeautifulSoup