2017/03/01 python 共 685 字,约 2 分钟

Python Extension Packages for Windows 上找到相应的库,解压后把bs4目录复制到Python安装目录下的lib目录下。 参考:Python爬虫利器二之Beautiful Soup的用法觅


from bs4 import BeautifulSoup

html = ...
soup = BeautifulSoup(html,"lxml")
print soup.title


<title>The Dormouse's story</title>
D:\Python27\lib\bs4\ 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")


Process finished with exit code 0



    Table of Contents