python - 使用python从HTML表格的行中提取文本
问题描述
我正在尝试使用 Python 从下面的 HTML 表中提取日出时间(上午 7 点 56 分),我用漂亮的汤刮掉了它。这是第二行的“文本右”,但我无法弄清楚或找到任何指导我的资源,我是否将表格循环到第二行?
第一道曙光 7:20 AM 日出 7:56 AM
<table class="table table-sm table-striped table-inverse table-tide">
<tr>
<td><strong>First Light</strong></td>
<td class="text-right"> 7:20AM</td>
</tr>
<tr>
<td><strong>Sunrise</strong></td>
<td class="text-right"> 7:56AM </td>
</tr>
</table>
原谅脏代码块
提前致谢。
解决方案
是的,您可以尝试像这样迭代 td 标记:
for td in soup.find_all('td', attrs={"class":"text-right"}):
print(td.text)
输出:
7:20AM
7:56AM
推荐阅读
- c - 将 exec() 的输出放入管道
- vue.js - 从 Vuetify 数据表单击时如何应用持久数据?
- google-chrome-extension - chrome.storage.sync 无法设置和获取
- sql - 选择除重复列之外的所有列,除非列的字符串长度最长
- ipfs - 从 js-ipfs 中的哈希获取文件
- arrays - 在 3D 向量的子向量上使用 matlab 中的范数函数
- c++ - 'void *' to 'void (*) (bool)' 使用 ac ++ 编译器在 c 中编译文件时出现指针错误
- javascript - 无法解析“css-loader!autoprefixer-loader”
- php - 带有 preg_replace_callback 的正则表达式用于亵渎过滤器
- java - 如何将开关传递给我的 Android 应用程序以控制其在开发过程中的行为?