本文介绍了beautifulsoup无法识别lxml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试将lxml用作BeautifulSoup的解析器,因为默认解析器要慢得多,但是我遇到此错误:

I'm attempting to use lxml as the parser for BeautifulSoup because the default one is MUCH slower, however i'm getting this error:

    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依赖项,而我仍然得到这个.

I have uninstalled and reinstalled lxml as well as beautifulsoup many times, however it still will not read it. I've tried reinstalled lxml dependencies as well and i'm still getting this.

我什至制作了一个新的虚拟环境,并重新安装了所有内容,仍然出现此错误.

I even made a new virtual environment and installed fresh everything and still get this error.

有人知道这是怎么回事吗?

Anyone have any idea whats going on here?

编辑

在ubuntu桌面上的python 2.7.x上使用bs4和lxml的最新版本

Using latest versions of bs4 and lxml on Python 2.7.x on ubuntu desktop

我可以import lxml,但我不能返回from lxml import etree:

i can import lxml but i cannot from lxml import etree that is returning:

  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,仍然没有任何操作

i have libxml however i'm not sure the version, but i installed and reinstalled the latest. also tried to manually install 2.9.0 and still nothing

推荐答案

lxml似乎尚未成功安装.要在Ubuntu上安装lxml,请运行

It looks like lxml has not been successfully installed. To install lxml on Ubuntu, run

sudo apt-get install libxslt1-dev libxml2

在virtualenv中:

In virtualenv:

pip install --upgrade lxml
pip install cssselect

这篇关于beautifulsoup无法识别lxml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 21:07