【发布时间】:2016-09-23 07:50:37
【问题描述】:
我一直在努力使用 BeautifulSoup 解析这棵树以获取我正在寻找的文本。在美化 HTML 之后,我得到了一个我感兴趣的表格。
<td>
<a href="/inventoryCheck/16783169/?zip=93817">
<h3>
Product A
</h3>
</a>
<a class="show_hide" href="/inventoryCheck/16783169/?zip=93817" style="color:red">
Not Available
</a>
<br/>
Available at roughly
<a style="color:red">
0%
</a>
of Stores Nationwide
</td>
</tr>
<tr>
<td style="padding:10px">
<a href="/inventoryCheck/32201303/?zip=93817">
<img src="/prod_image/32201303.jpg"/>
</a>
</td>
<td>
<a href="/inventoryCheck/32201303/?zip=93817">
<h3>
Product B
</h3>
</a>
<a class="show_hide" href="/inventoryCheck/32201303/?zip=93817" style="color:red">
Not Available
</a>
<br/>
Available at roughly
<a style="color:red">
0%
</a>
of Stores Nationwide
</td>
</tr>
<tr>
<td style="padding:10px">
<a href="/inventoryCheck/29236000/?zip=93817">
<img src="/prod_image/29236000.jpg"/>
</a>
</td>
<td>
<a href="/inventoryCheck/29236000/?zip=93817">
<h3>
Product C
</h3>
</a>
<a class="show_hide" href="/inventoryCheck/29236000/?zip=93817" style="color:red">
Not Available
</a>
<br/>
Available at roughly
<a style="color:red">
0%
</a>
of Stores Nationwide
</td>
</tr>
<tr>
<td style="padding:10px">
<a href="/inventoryCheck/35536199/?zip=93817">
<img src="/prod_image/35536199.jpg"/>
</a>
</td>
<td>
<a href="/inventoryCheck/35536199/?zip=93817">
<h3>
Product D
</h3>
</a>
<a class="show_hide" href="/inventoryCheck/35536199/?zip=93817" style="color:red">
Not Available
</a>
<br/>
Available at roughly
<a style="color:red">
0%
</a>
of Stores Nationwide
</td>
“h3”标签表示产品,所以我想获取该标签中的文本,如果有 h3,那么我还想查看下一个“a”标签,看看该产品是否可用。
最终在 Python 中,我只想要一行包含产品名称及其可用性的行。
我尝试过使用 .children、.descendants 等,但真的无济于事。
谁能提供线索。
【问题讨论】:
标签: python beautifulsoup