python - BeautifulSoup指定lxml作为解析器报错?
问题描述
环境:windows 10PyCharm 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已经导入了
请问我要怎么做才能解决这个问题呢?
万分感谢!
问题解答
回答1:找了其他人的代码看,终于知道是什么问题
并不是路径的问题,而是传参的问题
markup 其实是要解析的内容,例如:
soup = BeautifulSoup('<html>data</html>', 'lxml')
或者
markup = '<html>data</html>'soup = BeautifulSoup(markup, 'lxml')
PS. 在文档中没有函数参数列表之类的,不知道是不是找的位置错了...
回答2:pip install lxml
相关文章:
1. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?2. docker api 开发的端口怎么获取?3. golang - 用IDE看docker源码时的小问题4. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?5. docker start -a dockername 老是卡住,什么情况?6. 请问“由于 Cookie “PHPSESSID”的“SameSite”属性设置为“None”,但缺少“Secure”属性,此 Cookie 未来将被拒绝。”请问出现这个问题怎么办?7. docker容器呢SSH为什么连不通呢?8. Docker for Mac 创建的dnsmasq容器连不上/不工作的问题9. 前端 - 类到底该如何去命名 .newsList 这种的命名难道真的不是过度语义化吗?~10. 取不出SQL得到的当前页

网公网安备