- Beautiful Soup简介
- Beautiful Soup安装
- Beautiful Soup用法
Beautiful Soup简介
Beautiful Soup安装
- Windows 下命令行输入:pip install beautifulsoup4 即可。
Beautiful Soup用法
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc,"html.parser")
print soup
print type(soup)
print soup.prettify()# 按照标准的缩进格式的结构输出
# 通过标签名称来获取Tag对象,如果有多个相同的标签名称,返回第一个
print soup.html
print soup.body
print soup.title
print type(soup.title)# class类,tag标签
print soup.find_all('a')# 查找所有a标签
print soup.find_all('a')[2]# 查找第二个a标签
print soup.title.string# 输出字符串格式String
print soup.b.string # 输出注释
#find只返回第一个
print soup.find("id='''")