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

标签 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,所以我不确定查找括号中的内容是什么?

最佳答案

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

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

关于python - 使用 python 从 HTML 中的类中打印所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52975313/

相关文章:

python - BeautifulSoup 为 .find 和 .find_all 提供不同的结果

python - Python BeautifulSoup 4 文档中给出的示例

python - 如何用 0 替换空字符串,但如果不为空则保留它

Python导入错误 "DLL load failed"| Python

css - 如何设置父div高度自适应内层div高度?

html - 更改列表排列 - HTML 和 CSS

javascript - 使用开源浏览器模拟人类

python - 在 Cython 中使用 zlib 压缩 NumPy 数组

python - 如何从不同的目录导入模块并让它在该目录中查找文件

python - BeautifulSoup 获取多页文本