【发布时间】:2014-07-04 10:06:08
【问题描述】:
我正在使用 Beautiful Soup 进行一些网页抓取。我已将输出范围缩小到以下范围:
[<p><a class="puCloselink" href="javascript:window.close();" id="ctl00_CloseThisPage" onclick="javascript:window.close();" title="Close Window" usesubmitbehavior="false">Close Window</a></p>, <p class="txtBoxAlign">
<span style="display:none"><input id="Location" name="Location" type="hidden" value="48001"/>
</span>
<input id="newLocation" type="text"/>
<input id="GeoCode" name="GeoCode" type="hidden" value=""/>
<label for="newLocation">Address or ZIP Code (Required): </label>
</p>, <p class="PharmacyNameTxtBox txtBoxAlign">
<input id="PharmacyName" name="PharmacyName" type="text" value=""/>
<label for="PharmacyName">Pharmacy Name: </label>
</p>, <p>
<strong>CVS Pharmacy #</strong><br/>
1025 St Clair River Dr <br/>
Algonac, MI 48001<br/>
1-810-794-4941
</p>, <p>
Retail
</p>, <p>
Not applicable
</p>, <p>
<strong>Kroger Pharmacy</strong><br/>
2600 Pointe Tremble <br/>
Algonac, MI 48001<br/>
1-810-671-4002
</p>, <p>
Retail
</p>, <p>
Not applicable
</p>, <p>
<strong>Rite Aid Pharmacy 04943</strong><br/>
402 Pointe Tremble Road <br/>
Algonac, MI 48001<br/>
1-810-794-4985
</p>, <p>
Retail
</p>, <p>
Not applicable
</p>]
如您所见,有一些“p”标签内部带有“strong”,而一些“p”标签内部没有“string”。如何隔离整个“p”标签,但只针对那些包含“strong”的“p”?
谢谢。
【问题讨论】:
标签: python html web-scraping beautifulsoup