這是我想從中提取位置信息的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