如何摆脱BeautifulSoup用户警告?
问题内容:
安装BeautifulSoup之后,只要我在cmd中运行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")
我不知道为什么会出来以及如何解决它。
问题答案:
错误消息中明确说明了您的问题的解决方案。如下所示的代码未指定XML / HTML / etc。解析器。
BeautifulSoup( ... )
为了纠正错误,您需要指定要使用的解析器,如下所示:
BeautifulSoup( ..., "html.parser" )
您也可以根据需要安装第3方解析器。