python - BeautifulSoup指定lxml作为解析器报错?

查看:642
本文介绍了python - BeautifulSoup指定lxml作为解析器报错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

环境:
windows 10
PyCharm 2016.3.2

遇到问题:

刚开始学python,想用BeautifulSoup解析网页,但出现报错:

UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). 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.

The code that caused this warning is on line 4 of the file C:/Users/excalibur/PycharmProjects/learn/getMyIP.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "lxml")

  markup_type=markup_type))

然后根据提示和官网的文档加上:BeautifulSoup(markup, "html.parser")

结果出现了这样的报错:

在Google搜了下,都是说要导入路径,但是在 Settings -> Project -> Project Interpreter 里是这样的

显示BeautifulSoup已经导入了

请问我要怎么做才能解决这个问题呢?

万分感谢!

解决方案

找了其他人的代码看,终于知道是什么问题

并不是路径的问题,而是传参的问题

markup 其实是要解析的内容,例如:

soup = BeautifulSoup("<html>data</html>", "lxml")

或者

markup = "<html>data</html>"
soup = BeautifulSoup(markup, "lxml")

PS. 在文档中没有函数参数列表之类的,不知道是不是找的位置错了...

这篇关于python - BeautifulSoup指定lxml作为解析器报错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆