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

2024-06-16 11:00:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把某个班级的所有课文都打印在一页上,但找不到怎么打印

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,所以我不确定在find括号中应该输入什么?在


Tags: totextparserhtmlfunctionfindusingprint
1条回答
网友
1楼 · 发布于 2024-06-16 11:00:40
a = [i.text for i in dmenuhtml.findAll('div',{'class':'/class_name/'})]

试试这个。你需要知道你的文本在html中的位置。在

相关问题 更多 >