当前位置: 首页 > 工具软件 > A Tree > 使用案例 >

python解析错误:bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml

阳文轩
2023-12-01

bs4解析网站,报错

bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
几经周折才知道是bs4调用了python自带的html解析器,我用的mac,默认安装的是python2,所以内置的解释器也是捆绑在python2上,而我学习的时候又自己安装了python3,开发环境也是python3的,貌似是没有html解释器,所以会报错。
问题找到了,那么怎么解决呢?对,在python3也装一个html解析器就好了,那么怎么安装呢?查阅资料获悉:一般pip和pip2对应的是python2.x,pip3对应的是python3.x的版本,python2和python3的模块是独立的,不能混用,混用会出问题。所以命令行通过python3的pip:pip3 安装解析器:

$ pip3 install lxml
 

 类似资料: