这是我想从中提取位置信息的Web CSS。通过python字符串函数删除字符串附加字符
<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是什么? – 2016-06-01 07:01:47
他们都是那种格式吗?一些jbberish然后2个换行符然后是真正的文本? – Keatinge
试试这个解决方案http://stackoverflow.com/a/2743163/524743 – Samuel