【发布时间】:2022-09-30 12:21:10
【问题描述】:
如果我读取一个 html 文件并用 bs4 加载它,我会得到一个额外的 doctype 条目。我该如何预防?
HTML 代码
<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
<html>
<body>
<p>
text body
</p>
</body>
</html>
这就是文件的处理方式
from bs4 import BeautifulSoup
page = urllib.urlopen(file_name).read()
page_soup = BeautifulSoup(page, \'html.parser\')
生成的 HTML
<!DOCTYPE doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
<html>
<body>
<p>
text body
</p>
</body>
</html>
标签: python beautifulsoup