1

我在 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

永远感谢您的帮助!

4

1 回答 1

1

看看是否安装html5lib

pip install html5lib

然后提出这样的请求可以解决问题。

from bs4 import BeautifulSoup

data = open(directory +'\\'+ file)
soup = BeautifulSoup(data, 'html5lib')

这对我有用。

于 2018-03-05T18:46:32.830 回答