目录
  • 前言
  • 一、我的开发环境
  • 二、安装步骤
    • 1.安装BeautifulSoup库
    • 2.安装lxml类库
    • 3.测试安装结果
  • 三、 在pycharm中引入库
    • 总结 

      前言

      最近突然对爬虫有了一点兴趣,所以打算学一下爬虫,但是在安装使用一些库时,遇到了一些不小的麻烦,对于我来说,最麻烦的就是配置环境了,老是有一大堆莫名其妙的报错。。。

      今天记录一下,我如何在windows上安装BeautifulSoup库以及对应的lxml类库。 bs4本身有自己默认的解析器,但是这个默认的解析库实在太慢了,所以使用lxml类库可以大幅度提升解析速度

      一、我的开发环境

      • python3.6
      • windows
      • pycharm 2021.3(Community Edition)

      二、安装步骤

      1.安装BeautifulSoup库

      直接在命令行输入以下代码安装bs4。

      代码如下:

      pip3 install beautifulsoup4

      2.安装lxml类库

      使用pip直接安装lxml会出错。所以我选择在官网上下载对应python版本的lxml

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      将下载的文件放在cmd目录下,通过pip先安装wheel

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      代码如下:

      pip install wheel

      然后才能安装lxml对应的.whl文件

      安装完成后,进入python,import lxml 没有报错就成功啦

      3.测试安装结果

      进入python交互环境,引用bs4和lxml类库,如果安装成功,则不报错:

      import bs4
      import lxml
      

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      三、 在pycharm中引入库

      如果安装成功之后,运行python项目,还是报错:bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requests

      这时候需要在pycharm中引入相关的包。file->setting->python interpreter:

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      如果没有引入lxml,双击wheel,搜索lxml,安装,安装好后,就能查看到lxml包,运行项目,成功:

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      python项目报错:bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requests

      总结 

      声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。