使用python打印HTML中的类中的所有文本

时间:2018-10-24 17:59:13

标签: python html beautifulsoup

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

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不熟悉,所以不确定在查找括号中输入什么?

1 个答案:

答案 0 :(得分:0)

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

尝试类似这样的方法。您需要知道您的文本在html中的位置。