安装beautifulsoup后,运行测试报错

from urllib import request
from bs4 import BeautifulSoupurl = "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 orFeatureNotFound: 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")

python 报错 bs4 FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml相关推荐

  1. bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml. Do you need

    bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need ...

  2. 已解决bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: html5Lib. Do y

    已解决(bs4解析HTML网页报错)bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: ...

  3. python beautifulsoup报错bs4 FeatureNotFound Couldnot find a tree builder with the features

    运行bs4语句, soup=BeautifulSoup(html,"lxml") 出现如下错误:Traceback (most recent call last): File &q ...

  4. python出现—with the features you requested: lxml. Do you need to install a parser library?

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

  5. python 报错 IndentationError: expected an indented block SyntaxError: invalid character in identifie

    红色方框那里敲击一个空格就好! 输入要在全英情况下! 另外,还要注意括号的事情.括号别出错误! IndentationError: expected an indented block的报错: Syn ...

  6. Python安装库较慢问题,Python报错pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool解决方法

    本文参考:https://blog.csdn.net/sinat_26811377/article/details/99698807 出现问题 在安装第三方库的时候,Python报错pip._vend ...

  7. 解决Python报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 658: illegal multibyte

    解决Python报错–UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 658: illegal multibyte ...

  8. python报错UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe8 in position 0 解决方案

    python报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 0 解决方案 参考文章: (1)python报 ...

  9. Python 报错 SyntaxError: invalid syntax 解决方法

    Python 报错 SyntaxError: invalid syntax 解决方法 参考文章: (1)Python 报错 SyntaxError: invalid syntax 解决方法 (2)ht ...

最新文章

  1. Nginx启动提示找不到libpcre.so.1解决方法
  2. App启动闪屏黑屏问题
  3. C语言程序设计II—第八周教学
  4. 《零基础》MySQL 排序(十八)
  5. “烟花”来势汹汹!用数据可视化告诉你:台风最爱在哪登陆?
  6. python类的数组属性_Python学习之数组类型一:
  7. vue+video.js实现前端视频流(hls、MP4、flv)
  8. 支持android11的画质修改器,pubgtool画质修改器
  9. c语言程序文件夹里没看到prj,求教。如何调用编好的函数。如何使用prj文件
  10. win凭据添加计算机名,手动添加Windows凭据,彻底解决Win7系统打印共享-win7添加打印机...
  11. 如何dismiss多个viewController
  12. 奇迹 与服务器连接中断,奇迹少女连接服务器失败 连接不上网络怎么办
  13. 华硕fl8000u主板怎么拆_华硕顽石4笔记本 FL5900U如何打开后盖
  14. 百度网盘搜索工具汇总
  15. HGE编写游戏的心得体会
  16. 大数据必学Java基础(二十六):数组的应用题
  17. java int随机数_java的三种随机数生成方式
  18. jQuery入门jQuery API-1
  19. 本文带你了解透彻云计算(前世,今生,未来)
  20. Activity(一)—— Activity的启动流程

热门文章

  1. linux重启后出现control+D错误的解决
  2. Go 语言编程 — gormigrate GORM 的数据库迁移助手
  3. 安卓蓝牙调试软件和微信小程序搜索不到设备
  4. 洛谷 P1825 [USACO11OPEN]玉米田迷宫Corn Maze
  5. iOS - OC - XML 解析 - NSXMLParser
  6. 【转】How Many Boyfriends
  7. webpack 单页面应用实战
  8. LeetCode:Permutations II
  9. Zabbix-2.2.4,显示中文语言的选项方法
  10. java如何做到判断一个字符串是否是数字