通过beautifulsoup和re提取数据

我正试图从jb hifi中提取特殊信息,这是我所做的:


from BeautifulSoup import BeautifulSoup

import urllib2

import re




url="http://www.jbhifionline.com.au/support.aspx?post=1&results=10&source=all&bnSearch=Go!&q=ipod&submit=Go"


page=urllib2.urlopen(url)

soup = BeautifulSoup(page.read())

Item0=soup.findAll('td',{'class':'check_title'})[0]    

print (Item0.renderContents())

输出为:


Apple iPod Classic 160GB (Black) 

<span class="SKU">MC297ZP/A</span>

我想要的是:


Apple iPod Classic 160GB (Black)

我尝试使用re删除其他信息


 print(Item0.renderContents()).replace{^<span:,""} 

但这没用


所以我的问题是如何删除无用的信息并获得“ Apple ipod classic 160GB(黑色)”


www说
浏览 251回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python