1
大家好,我正在做一个python脚本,它需要从网站提取数据并将日期存储到sqlite3中。我在内容提取方面遇到了问题。这里是我做beatifulsoup从网页中提取数据python
#!/usr/bin/python
from BeautifulSoup import BeautifulSoup
import urllib2
import re
url="http://m.harveynorman.com.au/tv-audio/portable-audio/ipods"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
A=soup.findAll('strong',{'class':'name fn'})
for B in A:
print = B.renderContents()
代码和输出是这样的:
"iPod touch 16GB - White
iPod touch 4th Gen 32GB
Apple iPod Shuffle 2GB
iPod touch 16GB - Black
iPod nano 16GB
iPod touch 32GB"
,我尝试使用
print = B.renderContents()[0]
拿到指定一个插入到sqlite3的,但输出是这样的:
i
i
A
i
i
i
所以我的问题是如何提取指定的一个(如:iPod touch 16GB - 白色)?
欢呼伴侣每一行的,它的工作原理 –