def item_completed(self, results, item, info): # print(results) # [(True, {'url': 'https://rpic.douyucdn.cn/acrpic/170827/3034164_v1319.jpg', # 'checksum': '7383ee5f8dfadebf16a7f123bce4dc45', 'path': 'full/6faebfb1ae66d563476449c69258f2e0aa24000a.jpg'})] image_path = [x['path'] for ok, x in results if ok] os.rename(IMAGES_STORE + '/' + image_path[0], IMAGES_STORE + '/' + item['nickname'] + '.jpg') if not image_path: raise scrapy.DropItem('Image Downloaded Failed') return item
def post_mutasi_form(self, response): account_id = response.meta["account_id"] last_day = calendar.monthrange(int(self.year), int(self.month))[1] today = datetime.date.today() if today.day < last_day and today.month == int(self.month): last_day = today.day from_day = 1 six_month_ago = today - datetime.timedelta(days=6 * 30) if (today - datetime.timedelta(days=6 * 30)).month == int(self.month): from_day = today.day if ( six_month_ago.month < int(self.month) and int(self.year) > six_month_ago.year ): raise scrapy.DropItem("only six month query accepted") data = { "fromAccountID": account_id, "fromDay": str(from_day), "fromMonth": str(self.month), "fromYear": str(self.year), "toDay": str(last_day), "toMonth": str(self.month), "toYear": str(self.year), "action": "result", # 'sortType': 'Date', # 'orderBy': 'ASC', # 'searchType': 'R', } return scrapy.FormRequest.from_response( response, formname="TrxHistoryInqForm", formdata=data, callback=self.parse_mutation_page, # dont_filter=True, dont_click=True, meta={"dont_redirect": True}, )
def item_completed(self, results, item, info): image_paths = [x['path'] for ok, x in results if ok] if not image_paths: raise scrapy.DropItem('Image Download Failed') return item
def item_completed(self, results, item, info): # 是否下载成功 if not results[0]: raise scrapy.DropItem('download error') return item
def item_completed(self, results, item, info): image_paths = [x['path'] for ok, x in results if ok] if not image_paths: raise scrapy.DropItem("Item contains no images") item['image_paths'] = image_paths return item