我在Python27上运行了一个bs4程序,它运行正常,一旦我使用Python3,我就遇到了问题。我正在使用bs4的更新版本。我运行它的文件是html,我注意到错误在标签上。我需要更新支持模块吗?喜欢lxml?
码:
from bs4 import BeautifulSoup
data = open(directory +'\\'+ file)
soup = BeautifulSoup(data, 'html.parser')
这是错误:
...
File "C:\Anaconda3\lib\html\parser.py", line 174, in error
raise HTMLParseError(message, self.getpos())
html.parser.HTMLParseError: unknown status keyword 'NKXE' in marked section,
at line 318, column 49
永远感谢帮助!
看看是否安装了html5lib
pip install html5lib
然后像这样发出请求修复了这个问题。
from bs4 import BeautifulSoup
data = open(directory +'\\'+ file)
soup = BeautifulSoup(data, 'html5lib')
这对我有用。