我正在尝试使用 lxml
作为 BeautifulSoup 的解析器,因为默认的解析器要慢得多,但是我收到了这个错误:
soup = BeautifulSoup(html, "lxml")
File "/home/rob/python/stock/local/lib/python2.7/site-packages/bs4/__init__.py", line 152, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
lxml和beautifulsoup我都卸载重装了很多次了,还是不能读取。我也尝试重新安装 lxml 依赖项,但我仍然得到这个。
我什至创建了一个新的虚拟环境并重新安装了所有东西,但仍然出现此错误。
有人知道这里发生了什么吗?
编辑
在 ubuntu 桌面上的 Python 2.7.x 上使用最新版本的 bs4 和 lxml
我可以 import lxml
但我不能 from lxml import etree
返回:
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/x86_64-linux-gnu/libxml2.so.2: version `LIBXML2_2.9.0' not found (required by /home/rob/python/stock/local/lib/python2.7/site-packages/lxml/etree.so)
我有 libxml,但我不确定版本,但我安装并重新安装了最新版本。也试过手动安装 2.9.0 还是不行
最佳答案
看起来 lxml 没有安装成功。要在 Ubuntu 上安装 lxml
,请运行
sudo apt-get install libxslt1-dev libxml2
在虚拟环境中:
pip install --upgrade lxml
pip install cssselect
关于python - beautifulsoup 无法识别 lxml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21322948/