如何摆脱 BeautifulSoup 用户警告? [英] How to get rid of BeautifulSoup user warning?
本文介绍了如何摆脱 BeautifulSoup 用户警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
安装 BeautifulSoup 后,每当我在 cmd 中运行 Python 时,都会出现此警告.
After I installed BeautifulSoup, Whenever I run my Python in cmd, this warning comes out.
D:Applicationpythonlibsite-packageseautifulsoup4-4.4.1-py3.4.eggs4\__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")
我不知道它为什么会出现以及如何解决它.
I have no ideal why it comes out and how to solve it.
推荐答案
错误消息中明确说明了问题的解决方案.像下面这样的代码没有指定 XML/HTML/等.解析器.
The solution to your problem is clearly stated in the error message. Code like the below does not specify an XML/HTML/etc. parser.
BeautifulSoup( ... )
为了修复错误,您需要指定要使用的解析器,如下所示:
In order to fix the error, you'll need to specify which parser you'd like to use, like so:
BeautifulSoup( ..., "html.parser" )
如果您愿意,您也可以安装第 3 方解析器.
You can also install a 3rd party parser if you'd like.
这篇关于如何摆脱 BeautifulSoup 用户警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文