Skip to main content
 首页 » 编程设计

python之BeautifulSoup 在特定标题后得到表格

2025年05月04日17tintown

我如何定位 BS4 以在 <h3>64-bit deb for Ubuntu/Debian</h3> 之后的表格开始? ?有很多表,唯一不同的是表头。

<h3>Windows 64-bit</h3> 
<table width="600" border="1" align="center"> 
: 
</table> 
: 
<h3>64-bit deb for Ubuntu/Debian</h3> 
<table width="600" border="1" align="center"> 
: 
</table> 
: 

请您参考如下方法:

这行得通吗?

>>> for header in soup.find_all('h3'): 
...     if header.get_text() == '64-bit deb for Ubuntu/Debian': 
...         header.find_next_sibling() 
... 
<table align="center" border="1" width="600"> 
: 
</table>