我正在尝试打印页面上某个类的所有文本,但找不到方法,
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,所以我不确定查找括号中的内容是什么?
最佳答案
a = [i.text for i in dmenuhtml.findAll('div',{'class':'/class_name/'})]
尝试这样的事情。您需要知道文本在 html 中的位置。
关于python - 使用 python 从 HTML 中的类中打印所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52975313/