安装lxml HTML 解析器,需要c语言库? BeautifulSoup

来源:互联网 发布:知轩藏书 编辑:程序博客网 时间:2024/05/18 02:24

lxml安装

soup = BeautifulSoup(str1, 'lxml')

有时提示:bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

原因是没有安装 lxml,但需要C语言库


Python中lxml模块的安装_Linux教程_Linux公社-Linux系统门户网站

http://pypi.python.org/pypi/lxml/2.3/ 

easy_install lxml-2.3-py2.7-win-amd64.egg

Linux系统

第一步: 安装 libxml2

  • sudo apt-get install libxml2 libxml2-dev  
第二步: 安装 libxslt
  • sudo apt-get install libxlst libxslt-dev 
第三步: 安装 python-libxml2 和 python-libxslt
  • sudo apt-get install python-libxml2 python-libxslt
第四步: 安装 lxml
  • sudo easy_install lxml 


Window本地安装

安装lxml HTML 解析器,需要c语言库? - Python 入门 - 知乎 

http://link.zhihu.com/?target=http%3A//www.lfd.uci.edu/%7Egohlke/pythonlibs/%23lxml

pip install lxml‑3.4.4‑cp27‑none‑win_amd64.whl# (Python2.7, 64bit)


BeautifulSoup解析器有4种:

“html.parser”

“lxml”

“xml”

“html5lib”


部署:写入 Requirement.txt,让 Heroku自动安装


$ pip install -r requirements.txt
Collecting lxml==3.6.4 (from -r requirements.txt (line 37))
Downloading lxml-3.6.4-cp27-cp27m-manylinux1_x86_64.whl (4.2MB)
Installing collected packages: lxml


0 0