【发布时间】:2010-06-09 19:04:56
【问题描述】:
我想从 BeautifulSoup 中得到正确分隔的文本,必要时将标签变成空白。问题是换行符被折叠并且像<br/> 这样的标签没有呈现为空白。
<div class="companyInfo">
<p class="identInfo">
<acronym title="Standard Industrial Code">
SIC
</acronym>
:
<a href="/?SIC=3674">
3674
</a>
- SEMICONDUCTORS & RELATED DEVICES
<br />
State location: CA
</p>
</div>
如果我运行 BeautifulSoup(sampleHTML).text 我会得到以下信息:
u'SIC:3674- SEMICONDUCTORS & RELATED DEVICESState location: CA'
我想得到正确处理空格的东西,像这样:
u'SIC : 3674 - SEMICONDUCTORS & RELATED DEVICES State location: CA'
有什么建议吗?谢谢!
【问题讨论】:
-
谢谢,我认为你是对的。另外,我认为我最好使用“.content”而不是“.text”。
标签: python beautifulsoup