python 报错 bs4 FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml
安装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相关推荐
- 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 ...
- 已解决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: ...
- python beautifulsoup报错bs4 FeatureNotFound Couldnot find a tree builder with the features
运行bs4语句, soup=BeautifulSoup(html,"lxml") 出现如下错误:Traceback (most recent call last): File &q ...
- 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 ...
- python 报错 IndentationError: expected an indented block SyntaxError: invalid character in identifie
红色方框那里敲击一个空格就好! 输入要在全英情况下! 另外,还要注意括号的事情.括号别出错误! IndentationError: expected an indented block的报错: Syn ...
- Python安装库较慢问题,Python报错pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool解决方法
本文参考:https://blog.csdn.net/sinat_26811377/article/details/99698807 出现问题 在安装第三方库的时候,Python报错pip._vend ...
- 解决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 ...
- 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报 ...
- Python 报错 SyntaxError: invalid syntax 解决方法
Python 报错 SyntaxError: invalid syntax 解决方法 参考文章: (1)Python 报错 SyntaxError: invalid syntax 解决方法 (2)ht ...
最新文章
- Nginx启动提示找不到libpcre.so.1解决方法
- App启动闪屏黑屏问题
- C语言程序设计II—第八周教学
- 《零基础》MySQL 排序(十八)
- “烟花”来势汹汹!用数据可视化告诉你:台风最爱在哪登陆?
- python类的数组属性_Python学习之数组类型一:
- vue+video.js实现前端视频流(hls、MP4、flv)
- 支持android11的画质修改器,pubgtool画质修改器
- c语言程序文件夹里没看到prj,求教。如何调用编好的函数。如何使用prj文件
- win凭据添加计算机名,手动添加Windows凭据,彻底解决Win7系统打印共享-win7添加打印机...
- 如何dismiss多个viewController
- 奇迹 与服务器连接中断,奇迹少女连接服务器失败 连接不上网络怎么办
- 华硕fl8000u主板怎么拆_华硕顽石4笔记本 FL5900U如何打开后盖
- 百度网盘搜索工具汇总
- HGE编写游戏的心得体会
- 大数据必学Java基础(二十六):数组的应用题
- java int随机数_java的三种随机数生成方式
- jQuery入门jQuery API-1
- 本文带你了解透彻云计算(前世,今生,未来)
- Activity(一)—— Activity的启动流程