【发布时间】:2018-03-05 18:38:27
【问题描述】:
我在 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
永远感谢您的帮助!
【问题讨论】:
-
检查一下你的文件处理程序是否正在读取...
-
不确定您要什么。你的意思是什么是“数据”对象?因为我在 python27 中看到它是
. -
然后在python3它的TextIOWrapper: <_io.textiowrapper name="C:\\Users\\..txt" mode="r" encoding="cp1252">
标签: python html beautifulsoup python-2to3