【发布时间】:2016-09-30 09:39:39
【问题描述】:
这是我要从中提取位置信息的网络 CSS。
<div class="location">
<div class="listing-location">Location</div>
<div class="location-areas">
<span class="location">Al Bayan</span>
,
<span class="location">Nepal</span>
</div>
<div class="area-description"> 3.3 km from Mall of the Emirates </div>
</div>
我使用的 Python Beautuifulsoup4 代码是:
try:
title= soup.find('span',{'id':'listing-title-wrap'})
title_result= str(title.get_text().strip())
print "Title: ",title_result
except StandardError as e:
title_result="Error was {0}".format(e)
print title_result
输出:
"Al Bayanأ¢â‚¬آھ,أ¢â‚¬آھ
Nepal"
如何将格式转换为以下格式
['Al Bayan', 'Nepal']
获取此输出的代码的第二行应该是什么
【问题讨论】:
-
产生此输出的 HTML 是什么?
-
都是那种格式的吗?一些 jbberish,然后是 2 个换行符,然后是真正的文本?
-
@LutzHorn 它是一个美丽的soup4(python)
-
发布更多代码实际上可能会有所帮助。
标签: python string python-2.7 python-3.x beautifulsoup