# 安装: pip install bs4
from bs4 import BeautifuSoup
soup = BeautifuSoup(html,'lxml')
# 获取html中的所有文字
text = soup.get()
# 通过指定标签名字获取内容
text = soup.select('.hehe')[0].get_text() # 获取class名字是hehe的第一个的文本内容,推荐使用get_text()的方法
text = soup.select('.heh')[0].string # 有的时候会获取不到内容,不太推荐使用
img_url = soup.select('img.middle')[0].get('src')
网友评论