在windows上安装BS4
从BeautifulSoup下载安装包。
解压出来。
在cmd命令行切换到解压出来的文件夹下,执行python setup.py install进行安装(需要配置好python环境变量)。
命令行执行python
>>>from bs4 import BeautifulSoup
由于我是装的python3,在调用bs4类库时报了版本问题错误。
You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>'You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`)
这时需要将BeautifulSoup4文件夹中的bs4文件夹拷贝到python安装目录下的lib中,并且将python安装目录下的Tools/scripts/2to3.py文件也剪切到python安装目录下的lib中。
然后执行python 2to3.py bs4 -w即可。
伺候再输入from bs4 import BeautifulSoup就不报错了。