前言: Beautiful Soup 3 目前已经停止开发,推荐在现在的项目中使用Beautiful Soup 4,不过它已经被移植到BS4了,也就是说导入时我们需要 import bs4 。所以这里我们用的版本是 Beautiful Soup 4.3.2 (简称BS4),另外据说 BS4 对 Python3 的支持不够好,虽然我用的Python35,如果有小伙伴用的是 Python3 版本,可以考虑下载 BS3 版本。 自己搞网页数据爬取时,需要
from bs4 import BeautifulSoup
,所以在py程序运行中遇到了一系列错误…….
ImportError: No module named 'bs4'
错误如下:
Python如何安装模块:
1.下载BS4模块:
http://www.crummy.com/software/BeautifulSoup/bs4/download/4.3/beautifulsoup4-4.3.2.tar.gz
2.解压到Python安装目录下的根目录中:
3.运行cmd,进入解压缩后的目录(如果Python默认安装在C盘下,打开cmd之后可以使用cd …语句先返回根目录,再进入Python27\beautifulsoup4-4.3.2)
4.进入Python27\beautifulsoup4-4.3.2之后安装BS4模块:
执行:python setup.py install
可参考链接:http://www.cnblogs.com/victor5230/p/6397449.html
然而又出现错误:
ImportError: cannot import name 'HTMLParseError'
解决bs4在Python 3.5下出现“ImportError: cannot import name ‘HTMLParseError’”错误
pip --upgrade beautifulsoup4
可参考链接:http://blog.csdn.net/sinat_26599509/article/details/50609646
bs4.FeatureNotFound
又出现错误:如下
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
安装pip install lxml
可参考链接1:https://www.zhihu.com/question/49221958/answer/115712155 可参考链接2:http://study.163.com/forum/detail/1002230039.htm
竟然就好了!!!!!!!