Skip to content

Commit

Permalink
Fix default cat
Browse files Browse the repository at this point in the history
Change-Id: I8a0885abd7931876109fdc388ca66b8c430205a2
  • Loading branch information
刘晨星 committed Nov 8, 2020
1 parent 8165b03 commit 033b071
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions amazon/spiders/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import datetime
import scrapy
from amazon.items import BookItem

Expand All @@ -21,8 +22,9 @@ class AmazonSpider(scrapy.Spider):
}

def __init__(self, cat=None, url=None, node=None):
if cat and (node or url):
self.cat = cat
if cat is None:
self.cat = datetime.datetime.today().strftime('%Y%m%d')
if node or url:
if url:
self.start_url = url
else:
Expand All @@ -35,11 +37,6 @@ def start_requests(self):
meta={'category': self.cat},
callback=self.parse_book_follow_next_page
)]
return [scrapy.Request(
url,
meta={'category': cat},
callback=self.parse_book_follow_next_page
) for cat, url in self.start_urls.items()]

def parse_book_follow_next_page(self, response):
lis = response.xpath('//ul[contains(@class, "s-result-list")]/li') or \
Expand Down

0 comments on commit 033b071

Please sign in to comment.