爬取字段和图片 spider_getModelInformation
import urllib
import urllib2
import re
class Spider:
def getPage(self,pageIndex):
url="http://mm.taobao.com/json/request_top_list.htm?page="+str(pageIndex)
request=urllib2.Request(url)
response=urllib2.urlopen(request)
return response.read().decode('gbk')
def getContents(self,pageIndex):
page=self.getPage(pageIndex)
pattern=re.compile('<a class="lady-name" href="(.*?)".*?>(.*?)</a>.*?<strong>(.*?)</strong>.*?<span>(.*?)</span>',re.S)
items=re.findall(pattern,page)
for item in items:
print "Personal Address",item[0]
print "Name",item[1],"Age",item[2],"city",item[3]
def start(self,start,end):
for i in range(start,end+1):
print "This is NO.",i,"model"
self.getContents(i)
spider=Spider()
spider.start(1,5)