[英]BeautifulSoup HTMLparsingError between Python2 and Python3
我在 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')
这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.