1.有时候需要更新pip
python -m pip install --upgrade pip
2.安装beautifulsoup4
①进入python安装目录的scripts目录
pip install beautifulsoup4
3.使用beautifulsoup4
①from bs4 import BeautifulSoup
soup= BeautifulSoup( html,'html.parser',from_encoding='utf-8')#创建对象
②搜索节点(find_all,find)的使用方法
#find_all(name,attrs,string)
soup.find_alll('a') #查找所有为a的节点
soup.find_all('a',href='test.html',string='hello')#查找标签为a,属性href=test.html,内容为hello的节点
③获取节点的内容
node.name #获取节点标签名称
node['href']#获取查询到节点的href属性
node.get_text()#获取节点内容