练习一:爬取iot的门户网站中环保管家页面内容:
import requests
from bs4 import BeautifulSoup
url='http://www.ioteis.com/Stewardship.html'
response_data=requests.get(url)
response_data.encoding='utf-8'
#把html页面进行解析
soup=BeautifulSoup(response_data.text,'lxml')
#分析发现内容放在content1下面的div中
for hbgj in soup.select(".content1 "):
title=hbgj.select("div.title1 a")[0].text
content=hbgj.select('div.ptext')[0].text
print("标题为:{},内容为:{}".format(title,content))