【发布时间】:2017-09-14 00:28:02
【问题描述】:
我有以下 HTML:
<div id="infoTable">
<h4>
User
</h4>
<table>
<tbody>
<tr>
<td class="name">
<a href="/userpage/123">BillyBob12345</a>
</td>
</tr>
<tr>
<td class="name">
<a href="/userpage/124">JimBob43</a>
</td>
</tr>
</tbody>
</table>
<h4>
Super User
</h4>
<table>
<tbody>
<tr>
<td class="name">
<a href="/userpage/112">CookieMonster</a>
</td>
</tr>
</tbody>
</table>
</div>
基本上,我希望得到两个列表:
Users = [{"BillyBob12345" : "123"}, {"JimBob43" : "124"}]
SuperUsers = [{"CookieMonster" : "112"}]
我目前正在使用 Python 2.7 和 BeautifulSoup4,我能够找到所有用户,但我无法将他们分成各自的组。
【问题讨论】:
标签: python html parsing beautifulsoup nextsibling