安装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. git提交代码时,Unstaged changes如何过滤.class .log等文件

    在项目下创建一个.gitignore文件,内容如下: 可以在文件目录中加入这个文件,也可以在eclipse中项目下加入此文件 /target/表示忽略target文件夹下的内容 .class 表示忽略 ...

  2. React 学习过程中常见的错误

    1,  react报错Module not found: Error: Can't resolve     解决:  一般是加载文件的路径写错了:      

  3. 7#Java基本语句语法

    Java基本语句语法https://github.com/DuGuQiuBai/Java/blob/master/day03/day03%E6%80%BB%E7%BB%93.txt 1:位运算符(了解 ...

  4. Linux 常用命令,处理端口和Tomcat,mysql

    查看端口占用 1.lsof -i:端口号 2.netstat -tunlp|grep 端口号 都可以查看指定端口被哪个进程占用的情况 kill -9 进程号    强制结束进程 启动 1.使用 ser ...

  5. sklearn中报错ValueError: Expected 2D array, got 1D array instead:

    from sklearn.linear_model import LinearRegression lr = LinearRegression() print(tr_x.shape,tr_y.shap ...

  6. STM32F103单片机解密资料

    STM32F103单片机解密资料下载 一.STM32 32位ARM Cortex MCU 基于ARM® Cortex® M 处理器内核的 32位闪存微控制器STM32产品家族,为MCU用户开辟了一个全 ...

  7. node概述

    1.什么是node:“一个搭建在Chrome JavaScript运行时 上的平台,用于构建高速.可伸缩的网络程序.Node.js采用的事件驱动.非阻塞I/O模型,使它 既轻量又高效,并成为构建运行在 ...

  8. VMware Workstation 14永久激活密钥

    VMware Workstation是一款功能强大的桌面虚拟计算机软件,简单来说就是最强的中文虚拟机了,可以在桌面上运行不同的操作系统 VMware workstation 14永久激活密钥 : CG ...

  9. Windows上IOCP Socket事件模型管理

     1.IOCP 2.使用IOCP 1)创建完成端口CreateIoCompletionPort: 2)向完成端口添加管理句柄与管理用户数据: 3)异步发送一个管理的事件请求: 4)开启工作线程来处理I ...

  10. 2015年上海现场赛重现 (A几何, K暴力搜索)

    A: 题目链接 :https://vjudge.net/contest/250823#problem/A 参考 : https://www.cnblogs.com/helenawang/p/54654 ...