Python2和Python3之间的BeautifulSoup HTMLparsingError

问题描述 投票:1回答: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

永远感谢帮助!

python html beautifulsoup python-2to3
1个回答
1
投票

看看是否安装了html5lib

pip install html5lib

然后像这样发出请求修复了这个问题。

from bs4 import BeautifulSoup

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

这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.