看你抓的是静态还是动态的了,这里是静态表格信息的代码:
from BeautifulSoup import BeautifulSoup
import urllib2
import re
import string
def earse(strline,ch) :
left = 0
right = strline.find(ch)
while right !=-1 :
strline = strline.replace(ch,'')
right = strline.find(ch)
return strline
url = r"
http://www.bjsta.com" resContent = urllib2.urlopen(url).read()
resContent = resContent.decode('gb18030').encode('utf8')
soup = BeautifulSoup(resContent)
print soup('title')[0].string
tab= soup.findAll('table')
trs = tab[len(tab)-1].findAll('tr')
for trIter in trs :
tds = trIter.findAll('td')
for tdIter in tds :
span = tdIter('span')
for i in range(len(span)) :
if span[i].string :
print earse(span[i].string,' ').strip(),
else :
pass
print