安装BeautifulSoup后,每当我在命令行中运行Python时,就会发出以下警告:
D:\Application\python\lib\site-packages\beautifulsoup4-4.4.1-py3.4.egg\bs4\__init__.py:166:
UserWarning: No parser was explicitly specified, so I'm using the best
available HTML parser for this system ("html.parser"). This usually isn't a
problem, but if you run this code on another system, or in a different
virtual environment, it may use a different parser and behave differently.
To get rid of this warning, change this:
BeautifulSoup([your markup])
to this:
BeautifulSoup([your markup], "html.parser")我不知道为什么会出现这种情况,也不知道如何解决。
发布于 2015-11-04 00:14:53
错误信息中清楚地说明了解决问题的方法。下面这样的代码没有指定XML/HTML/etc解析器。
BeautifulSoup( ... )为了修复错误,需要指定要使用的解析器,如下所示:
BeautifulSoup( ..., "html.parser" )如果愿意,还可以安装第三方解析器。
发布于 2016-06-07 10:46:32
文档建议您安装并使用lxml以提高速度。
BeautifulSoup(html, "lxml")如果您使用的Python 2版本早于2.7.3,或者Python 3的版本早于3.2.2,那么安装lxml或html5lib(Python的内置HTML解析器)在旧版本中就不是很好了。
安装LXML解析器
发布于 2018-09-06 15:03:35
对于HTML解析器,您需要安装html5lib,运行:
pip install html5lib然后在html5lib方法中添加BeautifulSoup:
htmlDoc = bs4.BeautifulSoup(req1.text, 'html5lib')
print(htmlDoc)https://stackoverflow.com/questions/33511544
复制相似问题