找到相应的库,解压后把bs4目录复制到Python安装目录下的lib目录下。
#coding:utf-8要指定解释器,否则会报错:
from bs4 import BeautifulSoup
html = ...
soup = BeautifulSoup(html,"lxml")
print soup.title
<title>The Dormouse's story</title>
D:\Python27\lib\bs4\__init__.py:166: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
To get rid of this warning, change this:
BeautifulSoup([your markup])
to this:
BeautifulSoup([your markup], "lxml")
markup_type=markup_type))
Process finished with exit code 0