您可以使用以下方法:
import bs4soup = bs4.BeautifulSoup(html, 'html.parser')for e in soup: if isinstance(e, bs4.element.ProcessingInstruction): e.extract() breakprint(soup)
对于您的示例,这将为您提供更新的HTML:
<!DOCTYPE html><html lang="en"><head>...</head><body>...</body><html></html></html>



