安装beautifulsoup后,运行测试报错

from urllib import request
from bs4 import BeautifulSoup url = "http://www.baidu.com"
rsp = request.urlopen(url)
content = rsp.read() soup = BeautifulSoup(content, "lxml") print(soup.title.string)
----------------------------------------------------------------------
FeatureNotFound                      Traceback (most recent call last)
~/data/spider/bs.py in <module>
     16 content = rsp.read()
     17
---> 18 soup = BeautifulSoup(content, "lxml")
     19
     20 print(soup.title.string) ~/data/spider/venv/lib/python3.7/site-packages/bs4/__init__.py in __init__(self, markup, features, builder, parse_only, from_encoding, exclude_encodings, **kwargs)
    196                     "Couldn't find a tree builder with the features you "
    197                     "requested: %s. Do you need to install a parser library?"
--> 198                     % ",".join(features))
    199             builder = builder_class()
    200             if not (original_features == builder.NAME or FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

经过测试发现是lxml的问题,使用 pip install lxml 安装,安装完后,在运行还是一样出错, 经百度、知乎的说法是新的库不支持,新版本语法支持改变了

使用 pip install lxml时,自动安装的是最新 4.2.5版本

解决方法一:

  卸载新的换老的就可以了

    pip uninstall lxml

    pip install lxml==3.7.0

方法二:

 在报错代码中把函数参数中所有的"lxml"改成"html.parser"
soup = BeautifulSoup(content, "lxml")
改成 soup = BeautifulSoup(content, "html.parser")

bs4 FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?的更多相关文章

  1. 执行python 爬虫脚本时提示bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

    from bs4 import BeautifulSoupfrom urllib.request import urlopenimport re html = urlopen('http://**** ...

  2. Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

    python3.6.3  我在处理爬虫时候使用BeautifulSoup中遇到报错 “ bs4.FeatureNotFound: Couldn't find a tree builder with t ...

  3. python bs4解析网页时 bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to inst(转)

    Python小白,学习时候用到bs4解析网站,报错 bs4.FeatureNotFound: Couldn't find a tree builder with the features you re ...

  4. python报错bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.

    qpython运行 原代码:    soup = BeautifulSoup(r.text,'lxml') 报错:bs4.FeatureNotFound: Couldn't find a tree b ...

  5. bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml.

    python3 bs4解析网页时报错: bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requeste ...

  6. [error:没有解析库]Couldn't find a tree builder with the features you requested: xml. Do you need to install a parser library?

    将代码拷贝到服务器上运行,发生错误提示需要新安装parser library. 查看代码中发现有以下内容: soup = BeautifulSoup(open(fp), 'xml') 安装解析库即可: ...

  7. 【Python学习】爬虫报错处理bs4.FeatureNotFound

    [BUG回顾] 在学习Python爬虫时,运Pycharm中的文件出现了这样的报错: bs4.FeatureNotFound: Couldn’t find a tree builder with th ...

  8. Python 中常见错误总结

    IndentationError: unexpected indent Python 中强制缩进,, IndentationError: unexpected indent 缩进错误 这类错误非常常见 ...

  9. python运行selenium时出现的一个错误总结

    1.SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame 场景:运用pan ...

随机推荐

  1. .NET中结构和类的区别

    最近在学习Swift语言,看到了枚举这一章,Swift可以支持在枚举中定义方法...于是想到了回顾一下.NET中枚举.结构.类之间区别. 枚举在.NET较为简单,这里就不作比较,只谈谈结构和类. 1. ...

  2. CentOS 7 Gitlab+Jenkins持续集成+自动化部署

    基于上次的环境<部署Gitlab+Jenkins持续集成环境> 来实现自动化部署 系统管理–>插件管理–>安装以下插件: Credentials Plugin(默认已经安装) ...

  3. Winfon 页签切换及窗体控件自适应

    由于公司的业务调整,最近不仅开发bs,还有不熟悉的cs,人手也不足,项目还多,对于cs来说,算是小白,虽然是一个人,也是硬着头皮写,拖拽控件,自定义控件.一个项目下来,对cs有了很深的认识,这里好好感 ...

  4. 小程序如何封装自定义组件(Toast)

    1.创建和pages 同级的component目录新建一个myToast目录 例如: 2.myToast.wxml文件内容: <!-- 自定义toast组件 --> <!-- nam ...

  5. 团队的Kick off

    团队名称:Super power 团队介绍:我们是一个积极向上不乏活力快咯的团队,在一起的任务是happy高效地完成我们的项目. 团队成员自我介绍: 李洪超(项目经理):(男,帅)性格内向,爱好学习, ...

  6. 博客地址更改为csdn博客:https://blog.csdn.net/zysps1

    由于博客园不支持markdown的数学公式等语法,有时分享不方便,特更改阵地为csdn:https://blog.csdn.net/zysps1

  7. [Offer收割] 编程练习赛63

    题目1 : 命名 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 有两个公司想要合并,第一个公司的名字是一个字符串S,第二个公司的名字是一个字符串T. 合并后的新公司是这样 ...

  8. mybatis的collection查询问题以及使用原生解决方案的结果

    之前在springboot+mybatis环境的坑和sql语句简化技巧的第2点提到,数据库的一对多查询可以一次查询多级数据,并且把拿到的数据按id聚合,使父级表和子级表都有数据. 但是这种查询,必然要 ...

  9. GitHub 常用的几条命令

    初始化仓库 git init 下载仓库 git clone 仓库地址 将所有违背跟踪的文件添加到本地仓库 git add . 查看状态 git status 执行提交 git commit -m pr ...

  10. VueScroller 使用

    下载插件  npm install vue-scroller -D 引入插件: import Vue from 'vue'import VueScroller from 'vue-scroller' ...