python - 使用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,所以我不确定查找括号中的内容是什么?
解决方案
a = [i.text for i in dmenuhtml.findAll('div',{'class':'/class_name/'})]
尝试这样的事情。您需要知道您的文本在 html 中的位置。
推荐阅读
- python - 如何在手机屏幕中为“tinymce”设置小图标大小?
- python - 当从 csv 复制到“id”列中的空值时,复制命令不更新 Id_sequence 列违反非空约束
- react-native - 在 React Native 中更改目标元素的值
- reactjs - ReactJS:无法对未安装的组件执行 React 状态更新
- hibernate - 未调用实体侦听器
- kotlin - 使用在 Kotlin 中不起作用的格式对数字进行舍入
- javascript - hbs 没有在 node.js 中定义?
- c# - 如何在 C# 中获取文件的 Windows 文件资源管理器图标
- ruby-on-rails - 无法打开到 localhost:9200 的 TCP 连接 - Docker 上的 Rails
- json - 解析 Json 显示错误 keyNotFound Swift