Python爬虫——使用lxml库中的etree模块时显红报错,但又可以正常运行

ImportError: cannot import name ‘etree’ from ‘lxml’

今天在做网络爬虫的时候,需要用上xpath,环境中已经安装了lxml库,结果引入的时候,显红报错,如图所示:
在这里插入图片描述
在这里插入图片描述

我的环境是 python3.7.4 +lxml 4.4.1
编译器:PyCharm
在这里插入图片描述在这里插入图片描述
报错原因: python3.5之后的 lxml 库中不能直接引入etree模块,新的版本无法直接使用“from lxml import etree”

解决方法:两行代码搞定
在这里插入图片描述

发布了27 篇原创文章 · 获赞 7 · 访问量 2135

猜你喜欢

转载自blog.csdn.net/lucky_shi/article/details/104432159