예제 #1
0
    def getAlbum(self, Uid, Aid, directory=defaultDir):
        global rename_file
        plist = r'http://photo.renren.com/photo/%s/album-%s/bypage/ajax/v7?page=%d&pageSize=100'
        domain = "http://photo.renren.com/photo/%s/album-%s/v7" % (Uid, Aid)
        response = self.getHtml(domain)
        #
        metadata = xnString.getAlbumFromHtml(response.text)
        if metadata == None:
            self.work_msg("\t\t获取相册[ %s  %s ]信息失败,可能是因为加密\n" % (Uid, Aid))
            return
        #
        #self.__cnt += metadata['photoCount']
        #
        if metadata['photoCount'] == 0:
            return
        pageId = 1

        metadata['albumName'] = self.makeAlbumName(metadata['albumName'], Uid)

        adir = directory + xnString.checkDirName(metadata['albumName']) + '/'
        createFile(adir)
        if self.flag_pdm:
            self.work_msg("\t\t开始下载\t相册\t[%4d]\t<%s>" %
                          (metadata['photoCount'], metadata['albumName']))
        else:
            self.work_msg("\t\t开始下载\t相册\t[%4d]\t<%s>\n" %
                          (metadata['photoCount'], metadata['albumName']))
        while (pageId - 1) * 100 < metadata['photoCount']:
            while True:
                try:
                    page = plist % (Uid, Aid, pageId)
                    response = self.getHtml(page)
                    photolist = xnString.getPhotolist(response.text, page,
                                                      'getPhotolist')
                    break
                except:
                    pass
            if photolist:
                for photo in photolist:
                    url = photo['url']
                    pos = str(photo['position'])
                    if rename_file:
                        filename = adir + pos + xnString.getSuffix(url)
                    else:
                        #test
                        purl = url.split('/')
                        filename = adir + purl[-1]
                        #test
                    if os.path.exists(
                            filename) and os.path.getsize(filename) != 0:
                        continue
                    else:
                        self.__count()
                        self.__pool.add_job(self.getPicT, url, filename)
                    #getPic(photo, adir)
            else:
                self.work_msg("找不到photoList, User:%s Album:%s Page:%d\n" %
                              (Uid, Aid, pageId))
            pageId += 1
예제 #2
0
파일: xnSpider.py 프로젝트: xm45/xnSpider
	def getAlbum(self, Uid, Aid, directory = defaultDir):
		global rename_file
		plist = r'http://photo.renren.com/photo/%s/album-%s/bypage/ajax/v7?page=%d&pageSize=100'
		domain = "http://photo.renren.com/photo/%s/album-%s/v7"%(Uid,Aid)
		response = self.getHtml(domain)
		#
		metadata = xnString.getAlbumFromHtml(response.text)
		if metadata == None:
			self.work_msg("\t\t获取相册[ %s  %s ]信息失败,可能是因为加密\n"%(Uid,Aid))
			return
		#
		#self.__cnt += metadata['photoCount']
		#
		if metadata['photoCount'] == 0:
			return
		pageId = 1

		metadata['albumName'] = self.makeAlbumName(metadata['albumName'], Uid)

		adir = directory + xnString.checkDirName(metadata['albumName'])+'/'
		createFile(adir)
		if self.flag_pdm:
			self.work_msg("\t\t开始下载\t相册\t[%4d]\t<%s>"%(metadata['photoCount'],metadata['albumName']))
		else:
			self.work_msg("\t\t开始下载\t相册\t[%4d]\t<%s>\n"%(metadata['photoCount'],metadata['albumName']))
		while (pageId-1)*100 < metadata['photoCount']:
			while True:
				try:
					page = plist%(Uid, Aid, pageId)
					response = self.getHtml(page)
					photolist = xnString.getPhotolist(response.text, page, 'getPhotolist')
					break
				except:
					pass
			if photolist:
				for photo in photolist:
					url = photo['url']
					pos = str(photo['position'])
					if rename_file:
						filename = adir + pos + xnString.getSuffix(url)
					else:
						#test
						purl = url.split('/')
						filename = adir + purl[-1]
						#test
					if os.path.exists(filename) and os.path.getsize(filename) != 0:
						continue
					else:
						self.__count()
						self.__pool.add_job(self.getPicT, url, filename)
					#getPic(photo, adir)
			else:
				self.work_msg("找不到photoList, User:%s Album:%s Page:%d\n"%(Uid,Aid,pageId))
			pageId += 1
예제 #3
0
파일: xnSpider.py 프로젝트: xm45/xnSpider
	def getDirName(self, Uid, Uname = "", directory = defaultDir):
		Uname = Uname or self.getNameByUid(Uid)
		dirname = directory + xnString.checkDirName(Uname) + "   "+ Uid +'/'
		return dirname
예제 #4
0
 def getDirName(self, Uid, Uname="", directory=defaultDir):
     Uname = Uname or self.getNameByUid(Uid)
     dirname = directory + xnString.checkDirName(Uname) + "   " + Uid + '/'
     return dirname