【发布时间】:2021-04-16 17:33:23
【问题描述】:
我正在寻找解析 html 并使用 python 获取表 id 列表。
我有一个包含多个表格的以下格式的 HTML 文档:
我正在尝试抓取并获取表格 ID 的页面 - https://docs.aws.amazon.com/workspaces/latest/adminguide/workspaces-port-requirements.html
<html>
<div class="table-container">
<div class="table-contents disable-scroll">
<table id="w345aab9c13c11b5"> # this is table id for below table name
<thead>
<tr>
<th class="table-header" colspan="100%">
<div class="title">Domains and IP addresses to add to your allow list</div> # I need to look for this table name and get the table id associated with it
</th>
</tr>
</thead>
<tbody>
...
</tbody>
</table>
</div>
</div>
<div class="table-container">
<div class="table-contents disable-scroll">
<table id="w345aab9c13c13b2">
<thead>
<tr>
<th class="table-header" colspan="100%">
<div class="title">Domains and IP Addresses to Add to Your Allow List for PCoIP</div>
</th>
</tr>
<tr>
...
</tr>
</thead>
<tbody>
...
</tbody>
</table>
</div>
</div>
...
</html>
我需要检查div标签中的匹配值并获取与之关联的表ID
我是 python 新手,任何关于如何处理这个问题或解决方案的建议都会很有帮助。
【问题讨论】:
-
答案取决于您使用什么来获取 HTML。告诉我们你有什么。
-
感谢您的回复,请查看更新后的代码。 @JustinEzequiel
标签: python python-3.x dataframe web-scraping html-parsing