def get_apk(self, response): topic_url = referer_url = response.request.meta['referer_url'] update_date = time.strftime('%Y-m-%d %H:%M:%S') is_crawled = '1' priority_rating = '0' filename = ''.join([str(random.randrange(1,100000)), '.apk']) # if os.path.exists(''.join([os.getcwd(), os.sep, 'gfan', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) is False: # os.mkdir(''.join([os.getcwd(), os.sep, 'gfan', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) #调用新建文件夹的方法 down_dir = utils.make_spiderdir(self.platform, 'download') #解码:有的文件可能是utf-8编码,解为unicode try: filename = filename.decode('utf-8', 'ignore') except: pass filename = ''.join([down_dir, os.sep, str(time.time()).split('.')[0], filename]) open(filename, 'wb').write(response.body) #下载后在存数据库,确保准确性 hashurl = sql.hash_topic(topic_url) updatedate = time.strftime('%Y-%m-%d %H:%M:%S') filename = filename.replace('\\', '\\\\') insert_sql = sql.insert_softwareinfo(self.platform, hashurl, topic_url, updatedate, filename) status = handle_db(insert_sql) log.msg(str(status), log.DEBUG) #更新topic数据库表 insert_sql = sql.insert_topic_url(self.platform, topic_url,referer_url, updatedate, is_crawled, priority_rating) statusn = handle_db(insert_sql) log.msg(str(status), log.DEBUG) try: autocopy.copy(filename, self.platform) log.msg('copy job is successed', log.INFO) except: log.msg(str(traceback.print_exc()), log.ERROR) log.msg('copy job is failture', log.ERROR)
def get_apk(self, response): ''' 将下载地址下载的包写入文件,并且 ''' filename = response.request.meta['filename'] filename = ''.join([str(random.randrange(1,100000)), '.', filename]) # if os.path.exists(''.join([os.getcwd(), os.sep, 'xda', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) is False: # os.mkdir(''.join([os.getcwd(), os.sep, 'xda', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) #调用新建文件夹的方法 down_dir = utils.make_spiderdir(self.name, 'download') #解码:有的文件可能是utf-8编码,解为unicode try: filename = filename.decode('utf-8', 'ignore') except: pass filename = ''.join([down_dir, os.sep, str(time.time()).split('.')[0], filename]) open(filename, 'wb').write(response.body) #下载后在存数据库,确保准确性 topic_url = response.request.meta['topic_url'] hashurl = sql.hash_topic(topic_url) updatedate = time.strftime('%Y-%m-%d %H:%M:%S') filename = filename.replace('\\', '\\\\') insert_sql = sql.insert_softwareinfo(self.name, hashurl, topic_url, updatedate, filename) status = db.handle_db(insert_sql) log.msg(str(status), log.DEBUG) #更新topic数据库表 update_topic_url = sql.topicurl_withcrawed(topic_url) status = db.handle_db(update_topic_url) log.msg(str(status), log.DEBUG) #备份目录 try: autocopy.copy(filename, self.name) log.msg('copy job is successed', log.INFO) except: log.msg('copy job is failture', log.ERROR)
def get_apk(self, response): filename = ''.join([str(random.randrange(1,100000)), '.apk']) # if os.path.exists(''.join([os.getcwd(), os.sep, 'gfan', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) is False: # os.mkdir(''.join([os.getcwd(), os.sep, 'gfan', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) #调用新建文件夹的方法 down_dir = utils.make_spiderdir(self.platform, 'download') #解码:有的文件可能是utf-8编码,解为unicode try: filename = filename.decode('utf-8', 'ignore') except: pass filename = ''.join([down_dir, os.sep, str(time.time()).split('.')[0], filename]) open(filename, 'wb').write(response.body) #下载后在存数据库,确保准确性 topic_url = response.request.meta['topic_url'] hashurl = sql.hash_topic(topic_url) updatedate = time.strftime('%Y-%m-%d %H:%M:%S') filename = filename.replace('\\', '\\\\') insert_sql = sql.insert_softwareinfo(self.platform, hashurl, topic_url, updatedate, filename) status = handle_db(insert_sql) log.msg(str(status), log.DEBUG) #更新topic数据库表 update_topic_url = sql.topicurl_withcrawed(topic_url) status = handle_db(update_topic_url) log.msg(str(status), log.DEBUG) #能进入本方法执行,表示已经下载了该response.积分-1 account_sql = sql.select_accountbyusername(self.username, self.platform) point_num = handle_db(account_sql)['data'][0][5] point_num -= 1 #然后执行更新 update_account_pointsql = sql.update_account_point(self.username, self.platform, point_num) n = handle_db(update_account_pointsql) if n['errorNo'] == 0: log.msg(('<username: %s \'s integral is : -1 ,now integral is %s>' % (self.username, self.reply_num)), log.INFO) try: autocopy.copy(filename, self.platform) log.msg('copy job is successed', log.INFO) except: log.msg(str(traceback.print_exc()), log.ERROR) log.msg('copy job is failture', log.ERROR) request_topic = self.repeat_reply(response) return request_topic
def get_apk(self, response): filename = ''.join([str(random.randrange(1,100000)), '.ipa']) # if os.path.exists(''.join([os.getcwd(), os.sep, 'hiapk', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) is False: # os.mkdir(''.join([os.getcwd(), os.sep, 'hiapk', os.sep, 'download', os.sep, time.strftime('%Y-%m-%d'),os.sep])) #调用新建文件夹的方法 down_dir = utils.make_spiderdir(self.platform, 'download') #解码:有的文件可能是utf-8编码,解为unicode try: filename = filename.decode('utf-8', 'ignore') except: pass filename = ''.join([down_dir, os.sep, str(time.time()).split('.')[0], filename]) #下载后在存数据库,确保准确性 topic_url = response.request.url hashurl = sql.hash_topic(topic_url) updatedate = time.strftime('%Y-%m-%d %H:%M:%S') filename = filename.replace('\\', '\\\\') #插入数据库主题页面 insert_topic_sql = sql.insert_topic_url(self.name, topic_url, '', updatedate, '1', '0') topic_status = handle_db(insert_topic_sql) if topic_status['errorNo'] == -1: raise ValueError("this ipa file has download in my databases") open(filename, 'wb').write(response.body) insert_sql = sql.insert_softwareinfo(self.platform, hashurl, topic_url, updatedate, filename) status = handle_db(insert_sql) log.msg(str(status), log.DEBUG) try: autocopy.copy(filename, self.platform) log.msg('copy job is successed', log.INFO) except: log.msg(str(traceback.print_exc()), log.ERROR) log.msg('copy job is failture', log.ERROR)