首页 > 解决方案 > 使用python从HTML中的类中打印所有文本

问题描述

我正在尝试打印页面上某个类的所有文本,但找不到方法,

dmenuhtml = BeautifulSoup(dmenu, 'html.parser')

#print(dmenuhtml)

#using find function to parse through the html
allday_breakfast = dmenuhtml.find()
#converting to text
allday_breakfast2 = allday_breakfast.text.strip()

print ("The All Day Breakfast today features...\n")
print(allday_breakfast)

我不熟悉 HTML,所以我不确定查找括号中的内容是什么?

标签: pythonhtmlbeautifulsoup

解决方案


a = [i.text for i in dmenuhtml.findAll('div',{'class':'/class_name/'})]

尝试这样的事情。您需要知道您的文本在 html 中的位置。


推荐阅读