用beatifulsoup python从网页中提取数据
大家好,我正在做一个python脚本,需要从网站提取数据并将日期存储到sqlite3中。我在内容提取方面遇到了问题。这是我做的代码用beatifulsoup python从网页中提取数据,python,beautifulsoup,Python,Beautifulsoup,大家好,我正在做一个python脚本,需要从网站提取数据并将日期存储到sqlite3中。我在内容提取方面遇到了问题。这是我做的代码 #!/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 = Be
#!/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"
i
i
A
i
i
i
我试着用
print = B.renderContents()[0]
要获取要插入到sqlite3中的文件,请指定一个,但输出如下:
"iPod touch 16GB - White
iPod touch 4th Gen 32GB
Apple iPod Shuffle 2GB
iPod touch 16GB - Black
iPod nano 16GB
iPod touch 32GB"
i
i
A
i
i
i
所以我的问题是如何提取指定的一个(比如:iPod touch 16GB-白色)
屈服
iPod touch 16GB - White
是否打印每行的第一个字符
iPod touch 16GB - White
iPod touch 4th Gen 32GB
Apple iPod Shuffle 2GB
iPod touch 16GB - Black
iPod nano 16GB
iPod touch 32GB