我有以下 HTML:
<div class="dialog">
<div class="title title-with-sort-row">
<h2>Description</h2>
<div class="dialog-search-sort-bar">
</div>
</div>
<div class="content"><div style="margin-right: 20px; margin-left: 30px;">
<span class="description2">
With “Antonia Polygon – Standard”, you have a figure that is unique in the Poser community.
She is made available under a Creative Commons License that gives endless opportunities for further development.
This figure was developed by a group of talented members of the Poser community in a thirty-month effort.
The result is a figure that has very good bending and morphing behavior.
<br />
</span>
</div>
</div>
我需要从 的几个 div 中找到这个 div class="dialog"
,然后在span class="description2"
.
当我使用代码时:
description = soup.find(text = re.compile('Description'))
if description != None:
someEl = description.parent
parent1 = someEl.parent
parent2 = parent1.parent
description = parent2.find('span', {'class' : 'description2'})
print 'Description: ' + str(description)
我得到:
<span class="description2">
With “Antonia Polygon – Standard”, you have a figure that is unique in the Poser community.
She is made available under a Creative Commons License that gives endless opportunities for further development.
This figure was developed by a group of talented members of the Poser community in a thirty-month effort.
The result is a figure that has very good bending and morphing behavior.
<br/>
</span>
如果我尝试只获取文本,没有 HTML 和非 ASCII 字符,使用
description = description.get_text()
我得到一个(UnicodeEncodeError): 'ascii' codex can't encode character u'\x93'
如何将此 HTML 块转换为直接 ascii?