安装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. 使用datagrid时json的格式

    EasyUI的DataGrid要求返回的JSON数据集是这样的形式: {"total":总记录数量,"rows":[数据记录数组]}. 例如: {"t ...

  2. 六、latex中的特殊字符

  3. 003-单例OR工厂模式

    单例模式:DbContextFactory.cs using CZBK.ItcastOA.Model; using System; using System.Collections.Generic; ...

  4. git反悔

    Checkout checkout命令用于从历史提交(或者暂存区域)中拷贝文件到工作目录,也可用于切换分支. ![](./_image/2016-07-14 21-26-37.jpg?r=49) ![ ...

  5. 2017-2018-2 20155228 《网络对抗技术》 实验三:MAL_免杀原理与实践

    2017-2018-2 20155228 <网络对抗技术> 实验三:MAL_免杀原理与实践 实验内容 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasi ...

  6. [NOIP2015普及组]求和

    题目 题目描述 一条狭长的纸带被均匀划分出了n个格子,格子编号从1到n.每个格子上都染了一种颜色color_i用[1,m]当中的一个整数表示),并且写了一个数字numberi. 定义一种特殊的三元组: ...

  7. 2018.5.15Html标签初学

    body标签 -图标:&nbsp:(一个空格)&gt:(表示>)&lt:(表示<) -p标签:段落的划分 -br标签:换行 标签分为块级标签和行内标签. 块级标签: ...

  8. dataframe的进行json数据的压平、增加一列的id自增列

    {"name":"Michael", "age":25,"myScore":[{"score1":1 ...

  9. 对于react中rredux的理解

    1.什么是redux? redux是一个应用数据流框架,主要作用是对于应用状态的管理 2.reducer特点 : (1)默认的state (2)state是只可读不可修改 (3)必须返回一个纯函数 3 ...

  10. appium+python3+pycharm踩得坑

    错误: selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Ori ...